-
Notifications
You must be signed in to change notification settings - Fork 4
Backport diff-engine converter fixes to DNLP master #191
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
Changes from all commits
eb6ef2f
000667f
5e31272
287bc87
1af53dd
83e4dd5
ae88751
75a1630
d6f3a07
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 |
|---|---|---|
|
|
@@ -36,20 +36,16 @@ def convert_matmul(expr, children, var_dict, n_vars, param_dict): | |
|
|
||
| if left_arg.is_constant(): | ||
| A = left_arg.value | ||
| if isinstance(left_arg, cp.Parameter): | ||
| param_node = param_dict[left_arg.id] | ||
| else: | ||
| param_node = None | ||
| param_node = children[0] if left_arg.parameters() else None | ||
| if sparse.issparse(A): | ||
| return make_sparse_left_matmul(param_node, children[1], A) | ||
| return make_dense_left_matmul(param_node, children[1], A) | ||
|
|
||
| elif right_arg.is_constant(): | ||
| A = right_arg.value | ||
| if isinstance(right_arg, cp.Parameter): | ||
| param_node = param_dict[right_arg.id] | ||
| else: | ||
| param_node = None | ||
| if A.ndim == 1: | ||
| A = A.reshape(-1, 1) | ||
| param_node = children[1] if right_arg.parameters() else None | ||
| if sparse.issparse(A): | ||
| return make_sparse_right_matmul(param_node, children[0], A) | ||
| return make_dense_right_matmul(param_node, children[0], A) | ||
|
|
@@ -123,9 +119,14 @@ def convert_expr(expr, var_dict, n_vars, param_dict=None): | |
| d1_Python, d2_Python = normalize_shape(expr.shape) | ||
|
|
||
| if d1_C != d1_Python or d2_C != d2_Python: | ||
| raise ValueError( | ||
| f"Dimension mismatch for atom '{atom_name}': " | ||
| f"C dimensions ({d1_C}, {d2_C}) vs Python dimensions ({d1_Python}, {d2_Python})" | ||
| ) | ||
| # 1D shape (n,) normalizes to (1, n) but C may produce (n, 1); reshape. | ||
| if len(expr.shape) <= 1 and d1_C * d2_C == d1_Python * d2_Python: | ||
|
Collaborator
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. When can this happen? Let's talk on zoom and you can answer all my questions.
Member
Author
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. It happens in
Member
Author
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. honestly this is starting to get a lot of special casing for this weird numpy broadcasting for matmul cases.. but we are starting to understand better. |
||
| C_expr = _diffengine.make_reshape(C_expr, d1_Python, d2_Python) | ||
| else: | ||
| raise ValueError( | ||
| f"Dimension mismatch for atom '{atom_name}': " | ||
| f"C dimensions ({d1_C}, {d2_C}) vs " | ||
| f"Python dimensions ({d1_Python}, {d2_Python})" | ||
| ) | ||
|
|
||
| return C_expr | ||
Uh oh!
There was an error while loading. Please reload this page.