Repository navigation
Studio: build the ConvRot rotation from its definition - #11807
Conversation
Assemble the normalized H4 kron-power Hadamard from its closed-form sign pattern instead of repeated kron, and simplify the block rotation helpers. Output is bit-identical to the previous construction for every size and dtype, so hosted ConvRot checkpoints are unaffected. Comments now describe the rotation in neutral terms. Adds tests pinning bitwise equality with an inline kron reference for sizes 4..1024 in fp32/fp16/bf16 (CPU and CUDA), exact orthogonality, and agreement of the activation and weight rotations with an explicit block diagonal.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 010785292e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # a base-4 digit is 3 when both of its bits are set: keep the low bit of each such pair | ||
| threes = both & (both >> 1) & 0x5555555555555555 | ||
| parity = torch.zeros_like(threes) | ||
| while bool(threes.any()): |
There was a problem hiding this comment.
Replace tensor-dependent loop to preserve fullgraph compilation
On a cold Hadamard cache, a compiled ConvRotLinear.forward enters this loop and evaluates bool() on a tensor value, which TorchDynamo cannot capture under the normal fullgraph=True regional compilation configured in diffusion_speed.py. This occurs, for example, when MiniMax-H3 uses the ConvRot INT8 denoiser with the dense text encoder, so the conditioner has not already populated this cache; the first denoiser forward then drops the quantized block to the eager fallback, which this codebase documents as roughly 30× slower. Iterate a fixed number of base-4 digits derived from the Python size instead of using tensor data as the termination condition.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0e8b5e7: the parity loop now runs a fixed number of base-4 digits taken from the Python size. A cold-cache fullgraph compile of a rotated projection failed with a data-dependent guard error before and traces cleanly now; new test covers it.
The sign parity loop stopped on a tensor value, which Dynamo cannot trace under fullgraph=True, so a rotated projection whose first forward builds the matrix failed the regional compile. Loop over the fixed number of base-4 digits taken from the Python size instead.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
* Studio: build the ConvRot rotation from its definition Assemble the normalized H4 kron-power Hadamard from its closed-form sign pattern instead of repeated kron, and simplify the block rotation helpers. Output is bit-identical to the previous construction for every size and dtype, so hosted ConvRot checkpoints are unaffected. Comments now describe the rotation in neutral terms. Adds tests pinning bitwise equality with an inline kron reference for sizes 4..1024 in fp32/fp16/bf16 (CPU and CUDA), exact orthogonality, and agreement of the activation and weight rotations with an explicit block diagonal. * Studio: keep the ConvRot Hadamard build traceable under fullgraph The sign parity loop stopped on a tensor value, which Dynamo cannot trace under fullgraph=True, so a rotated projection whose first forward builds the matrix failed the regional compile. Loop over the fixed number of base-4 digits taken from the Python size instead. * Trim ConvRot comments
What
Rewrites the ConvRot rotation helpers in
studio/backend/core/inference/diffusion_convrot.pyas our own implementation:build_convrot_hadamardnow assembleskron(H4, ..., H4) / sqrt(n)from its closed-form sign pattern (entry(i, j)is negative when an odd number of base-4 digits ofi ^ jequal 3) instead of repeatedkron. The normalizer is an exact power of two.rotate_convrot_activation/rotate_convrot_weight_are simplified; names, signatures and caching are unchanged, so callers (including the H3 conditioner) are untouched.diffusion_convrot.py,video_minimax_h3_te.pyand the ConvRot test now describe the rotation in neutral terms.Why
Hosted ConvRot checkpoints were rotated with this exact matrix, so the output must not move. It does not: the new matrix and the rotated activations and weights are bitwise equal to the previous code for sizes 4..4096 in fp32/fp16/bf16 on CPU and CUDA, including non-contiguous inputs (276 checks, 0 mismatches).
Tests
New tests in
tests/test_diffusion_convrot.py:Results:
test_diffusion_convrot.py84 passed. ConvRot, H3 INT8 and prequant suites (test_video_h3_te_quant,test_diffusion_prequant,test_diffusion_pipeline_prequant,test_diffusion_te_prequant,test_build_prequant_checkpoint,test_prequant_safetensors,test_video_prequant,test_video_minimax_h3_adaln): 429 passed, 1 skipped, 1 failed. The one failure (test_the_read_layer_matches_the_diffusers_pipeline) is a local bitsandbytes import error inside diffusers and fails identically on main.test_sd_cpp_h3_matrixandtest_diffusion_h3_trainer: 275 passed, 6 skipped.