[vLLM IR] 2/N batch-invariant-aware dispatching and rms_norm#36816
[vLLM IR] 2/N batch-invariant-aware dispatching and rms_norm#36816ProExpertProg wants to merge 1 commit intoluka/vllm-ir/rms-normfrom
Conversation
Signed-off-by: Luka Govedič <lgovedic@redhat.com>
There was a problem hiding this comment.
Code Review
This pull request introduces the concept of batch-invariance for IR ops, which is a good step towards more efficient dispatching. A new has_reduction flag is added to IrOp to control the default batch_invariant status of its implementations. However, I've found a critical issue in how the batch_invariant flag is set for native PyTorch implementations. It's hardcoded to True, which is incorrect for reduction operations and inconsistent with how other implementations are handled. This could lead to incorrect behavior and numerical results when the dispatcher is implemented. My review includes a suggestion to fix this inconsistency.
| self.impls["native"] = IrOpImpl( | ||
| self, "native", native_impl, supported=True, supports_args=None | ||
| self, | ||
| "native", | ||
| native_impl, | ||
| # always supported | ||
| supported=True, | ||
| supports_args=None, | ||
| # Native implementation is always batch-invariant | ||
| # (batch invariance is controlled at the torch level) | ||
| batch_invariant=True, | ||
| ) |
There was a problem hiding this comment.
The native implementation is being hardcoded as batch_invariant=True. This seems incorrect for reduction operations and is inconsistent with the handling of other implementations.
For an op registered with has_reduction=True, its native PyTorch implementation (e.g., torch.sum) is generally not batch-invariant. Applying it to a batched tensor would typically reduce across the batch dimension, which is not the desired behavior for batch processing.
The logic for determining batch_invariant for non-native implementations (which defaults to not self.has_reduction) is sound and should also be applied to the native implementation for consistency. This ensures that all implementations for a reduction op are correctly marked as non-batch-invariant by default.
self.impls["native"] = IrOpImpl(
self,
"native",
native_impl,
# always supported
supported=True,
supports_args=None,
batch_invariant=not self.has_reduction,
)
Purpose
Test Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.