Skip to content

feat(nodes)!: BlockScaleSumParams applies the z-correction (dual-flow EM) by default - #63

Merged
liuanji merged 1 commit into
mainfrom
blockscale-z-correction-default
Oct 12, 2026
Merged

liuanji merged 1 commit into
mainfrom
blockscale-z-correction-default

Conversation

@liuanji

@liuanji liuanji commented Oct 12, 2026

Copy link
Copy Markdown
Member

BlockScaleSumParams(apply_z_correction = ...) now defaults to True: a gated sum node gets the exact M-step under its gate unless it opts out.

What the default now does. The backward also accumulates the denominator flow F-, and FullBatchEM / MiniBatchEM / Anemone update theta <- normalize(theta * F+ / F-).

  • F- is kept in gate space, ch_block_size times smaller than param_flows.
  • It costs about 1% of an EM step.

With apply_z_correction = False the layer allocates nothing and takes the plain M-step theta <- normalize(F+), as before.

Breaking

  • Node-axis gates finer than the node block (block_size < ns.block_size) are not served by the correction. Their backward raises NotImplementedError, whose message now says to pass apply_z_correction = False.
  • Gradient optimizers (SGD / Adam) still warn on a circuit that requests F-. A gated model trained with them now warns unless it is built with False.

Tests

  • denom_param_flows_test: the default is asserted on, and the mixed plain / gated sum group now runs with F- allocated.
  • test_a_node_axis_gate_computes_the_right_flows passes False where the gate is finer than the node block, as does test_a_node_axis_gate_is_captured.
  • Run: every BlockScale test file plus tests/optim, 773 passed, 12 skipped. The three edited files were re-run after the fix. None of them is marked slow.

… EM) by default

apply_z_correction now defaults to True: a gated sum node gets the exact M-step under its gate unless it passes
apply_z_correction = False. The backward accumulates the denominator flow F- (in gate space, ch_block_size times
smaller than param_flows; about 1% of an EM step) and FullBatchEM / MiniBatchEM / Anemone update
theta <- normalize(theta * F+ / F-). With False the layer allocates nothing and takes the plain M-step, as before.

Breaking: a gate finer than ns.block_size along the node axis is not served by the correction, and its backward
raises NotImplementedError, now naming apply_z_correction = False as the way out. Gradient optimizers still warn
on a circuit that requests F-, so a gated model trained with SGD / Adam now warns unless built with False.

- Tests: the default asserted on; the node-axis gate flow test passes False where the gate is finer than the node
  block, as does its CUDA-graph capture test; the mixed plain / gated sum group now runs with F- allocated.
@liuanji
liuanji merged commit 3b44e32 into main Oct 12, 2026
1 check passed
liuanji added a commit that referenced this pull request Oct 22, 2026
Brings in #62: the sum layers' precision option, the cuBLAS dense path, the tf32x3 backward, and the shared choice of
the tlmm fast path. #63, the z-correction default, is on this branch already as 1ed9d48.

Conflicts: tensorcircuit.py and block_scale.py, both split into modules on this branch. Both take the branch's side.
tensorcircuit.py adds #62's import of PRECISIONS and _pop_removed_precision_flags, and #62's change to the element-flow
helper goes to model/inspection.py, where that helper now lives. block_scale.py's split modules already carry #63.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant