Migrate sparse_matmul off brainevent's deprecated yw_to_w protocol#135
Merged
Conversation
brainevent 0.1.2 renames its DataRepresentation trace protocol from yw_to_w/yw_to_w_transposed to dt2t/dt2t_transposed, keeping the old names as deprecated aliases slated for removal. Switch sparse.py (and its test stubs) to call dt2t/dt2t_transposed directly and raise the minimum brainevent version to 0.1.2. Also fixes a pre-existing JAX-internal linear_util.wrap_init DeprecationWarning in the single-step VJP residual construction by threading a DebugInfo object through the ecosystem-standard brainstate._compatible_import.wrap_init shim.
Reviewer's GuideMigrates braintrace’s sparse matmul integration from brainevent’s deprecated yw_to_w* protocol to the new dt2t* protocol, updates stubs/tests/docs accordingly, bumps the brainevent minimum version, and fixes a JAX linear_util.wrap_init deprecation warning by routing VJP residual construction through the ecosystem wrap_init shim. Sequence diagram for sparse_matmul using brainevent DataRepresentation.dt2t_transposedsequenceDiagram
actor User
participant sparse_matmul
participant _sp_mm_dt_to_t
participant jax_vmap as jax.vmap
participant DataRepresentation
User->>sparse_matmul: sparse_matmul(x, weight_data, sparse_mat)
sparse_matmul->>_sp_mm_dt_to_t: _sp_mm_dt_to_t(hidden_dim, trace, sparse_mat)
_sp_mm_dt_to_t->>DataRepresentation: _unwrap_sparse_mat(sparse_mat)
alt hidden_dim.ndim == 2
_sp_mm_dt_to_t->>jax_vmap: jax.vmap(DataRepresentation.dt2t_transposed)
jax_vmap->>DataRepresentation: dt2t_transposed(hidden_dim_batch, weight_trace_batch)
else
_sp_mm_dt_to_t->>DataRepresentation: dt2t_transposed(hidden_dim, weight_trace)
end
_sp_mm_dt_to_t-->>sparse_matmul: out['weight']
sparse_matmul-->>User: y_sp
Sequence diagram for VJP residual construction using wrap_init shimsequenceDiagram
participant call_over_single_step
participant wrap_init
participant flatten_fun as jax.api_util.flatten_fun_nokwargs
participant trace_jaxpr as pe.trace_to_jaxpr_dynamic
call_over_single_step->>call_over_single_step: vjp_cotangent_args = ((out_single_or_multi_steps, etrace_state_vals, other_state_vals),)
call_over_single_step->>call_over_single_step: out_flat, out_tree = jax.tree.flatten(vjp_cotangent_args)
call_over_single_step->>wrap_init: wrap_init(f_vjp, vjp_cotangent_args, {}, braintrace_vjp_residual)
wrap_init-->>call_over_single_step: wrapped_f_vjp
call_over_single_step->>flatten_fun: flatten_fun_nokwargs(wrapped_f_vjp, out_tree)
flatten_fun-->>call_over_single_step: rule, in_tree
call_over_single_step->>trace_jaxpr: trace_to_jaxpr_dynamic(rule, out_avals)
trace_jaxpr-->>call_over_single_step: jaxpr, consts
call_over_single_step->>call_over_single_step: residual = VjpResiduals(jaxpr, in_tree(), out_tree, consts)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
brainevent0.1.2 renames itsDataRepresentationtrace protocol fromyw_to_w/yw_to_w_transposedtodt2t/dt2t_transposed(mirroringbraintrace's own
DT_TO_Trename in Rename YW_TO_W ETP rule to DT_TO_T #130), keeping the old names asdeprecated aliases slated for removal.
braintrace._op.sparsenow calls.dt2t/.dt2t_transposeddirectly instead of the deprecated aliases, andthe test stubs (
_StubSparseMat,_HashableStub,_DuckMat) are updated tomatch. Minimum
braineventis raised to 0.1.2 inpyproject.toml/requirements.txt.linear_util.wrap_initDeprecationWarningin the single-step VJP residual construction(
vjp_graph_executor.py), by threading aDebugInfoobject through theecosystem-standard
brainstate._compatible_import.wrap_initshim(re-exported as
braintrace._compatible_imports.wrap_init), matching thepattern already used elsewhere in the
brainstate/saiunitstack.docs/tutorials/etp_primitives.ipynb(braineventprotocol reference only — the notebook's stale
ETP_RULES_YW_TO_Wreferencesto braintrace's own pre-Rename YW_TO_W ETP rule to DT_TO_T #130 rule name are a separate, pre-existing issue
and out of scope here).
No behavior change; both migrations are mechanical/annotation-only.
Test plan
pytest braintrace/— 2123 passed, 0 failed, 3 skipped (matches baseline)pytest braintrace/_op/sparse_test.py braintrace/nn/_linear_test.py -W error::DeprecationWarning— 107 passed, zero brainevent/JAX deprecation warnings surfacedmypy braintrace— no issues foundSummary by Sourcery
Migrate sparse matmul and related tests to brainevent’s updated dt2t/dt2t_transposed trace protocol and address a JAX wrap_init deprecation in the VJP graph executor, with corresponding documentation and dependency updates.
Enhancements:
Build:
Documentation:
Tests: