-
Notifications
You must be signed in to change notification settings - Fork 1.3k
chore: improve ktransformers maintenance path #2033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,11 +30,11 @@ | |||||
| validation_iter = 100 | ||||||
|
|
||||||
|
|
||||||
| def act_fn(x): | ||||||
| def act_fn(x: torch.Tensor) -> torch.Tensor: | ||||||
| return x / (1.0 + torch.exp(-x)) | ||||||
|
|
||||||
|
|
||||||
| def mlp_torch(input, gate_proj, up_proj, down_proj): | ||||||
| def mlp_torch(input: torch.Tensor, gate_proj: torch.Tensor, up_proj: torch.Tensor, down_proj: torch.Tensor) -> torch.Tensor: | ||||||
| gate_buf = torch.mm(input, gate_proj.t()) | ||||||
| up_buf = torch.mm(input, up_proj.t()) | ||||||
| intermediate = act_fn(gate_buf) * up_buf | ||||||
|
|
@@ -95,4 +95,4 @@ def mlp_torch(input, gate_proj, up_proj, down_proj): | |||||
|
|
||||||
| diff = torch.mean(torch.abs(output - t_output)) / torch.mean(torch.abs(t_output)) | ||||||
| print("diff = ", diff) | ||||||
| assert diff < 0.001 | ||||||
| assert diff < 0.001, f"MLP output mismatch: diff={diff:.4e} exceeds threshold 0.001" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable
Suggested change
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
diff_relative_meanis a PyTorchTensor(0-dimensional). Directly formatting a PyTorch tensor with float format specifiers like:.4ecan raise aTypeErroror produce unexpected formatting in older PyTorch versions. It is safer and more idiomatic to call.item()to retrieve the underlying Python float before formatting.