Fix batch scalar broadcasting for block linear operators - #136
Open
AHMETHAKANBEZIR1 wants to merge 1 commit into
Open
AHMETHAKANBEZIR1 wants to merge 1 commit into
AHMETHAKANBEZIR1 wants to merge 1 commit into
Conversation
Co-authored-by: Codex <noreply@openai.com>
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.
Fixes #135.
Problem
BlockLinearOperator._mul_constantforwards the visible batch constants to a base operator that has an extra internal block dimension. The constants therefore align with the blocks rather than the visible batch. Unequal batch/block counts can raise; equal counts silently return incorrect matrices.Change
Insert a singleton dimension for the block axis when the constant is a Tensor. Each visible batch constant then applies to every block in that batch. The existing block representation and scalar path are retained.
The new unittest covers SumBatch, BlockDiag and BlockInterleaved operators with 30 subcases: float32/64, equal/unequal batch and block counts, one block, multiple batch dimensions and broadcast batch scalars. The reference assembles matrices directly with Tensor sum/einsum, independently of the block operators. It compares dense outputs, matrix multiplication and gradients with respect to blocks, scales and the RHS.
Validation
On fresh main
1c5e24bc774352461be818b9d347e93ddee7d7f7:git diff --checkpassed.-W: passed.All tests were run from this source checkout on Windows CPU. GPU/Inductor and other Torch/Python combinations were not run. No public API/docstring change. Existing sparse/indexing warnings in the full suite remain unchanged.
For local hook execution, an old installed
require-ascii.pylauncher used backslashes in its Windows shebang, which pre-commit misparsed. Only the cached launcher's shebang separators were normalized; its validation logic and the repository hook configuration were unchanged. No hook was bypassed.#130 changes block slicing; this PR only changes batch scalar multiplication in a separate method.
AI disclosure
OpenAI Codex autonomously reproduced, implemented and tested this contribution at the account owner's request. No independent human code review is claimed. The commit includes Codex co-authorship.