ops: reject non-contiguous MoE weights - #4
Open
morluto wants to merge 1 commit into
Open
Conversation
Signed-off-by: morluto <76467478+morluto@users.noreply.github.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 #3.
TL;DR
Reject non-contiguous MoE weight operands before they reach ThunderKittens'
tensor_to_glconversion and TMA-backed kernels.Problem
The fused BF16 and MXFP8 wrappers checked weight shapes and devices but not contiguity. MoK's C++ entry points convert these operands directly with
kittens::py::tensor_to_gl, bypassing the contiguity validation provided by ThunderKittens' higher-level object path.Change
mok/ops.py.ValueErrorbefore the CUDA entry point is called; no implicit.contiguous()copy is introduced.Review order
mok/ops.py: the validation boundary and the four affected operand sets.tests/test_ops.py: one shape-preserving non-contiguous weight case per wrapper.There are no generated or mechanical files in this change.
Regression coverage
The tests use
as_stridedto create a same-shaped non-contiguous shared weight and assert that each BF16/MXFP8 forward/backward wrapper raisesValueErrorduring Python validation.Validation
python -m py_compile mok/ops.py tests/test_ops.py— passedgit diff --check— passedNote
Low Risk
Defensive input checks only; fails fast on invalid layouts without changing kernel behavior for already-contiguous tensors.
Overview
Adds
_validate_contiguous_tensorsinmok/ops.pyand calls it on shared/routed MoE weights (and MXFP8 scale tensors where applicable) in the fourdispatch_mlp_swiglu_combine_*forward/backward wrappers, after shape checks and before_C/ ThunderKittenstensor_to_glpaths.Non-contiguous operands now raise a clear
ValueError("{name} must be contiguous"); there is no silent.contiguous()copy.tests/test_ops.pyadds anas_stridedhelper and one non-contiguous weight negative case per BF16/MXFP8 fwd/bwd wrapper.Reviewed by Cursor Bugbot for commit 915468a. Bugbot is set up for automated code reviews on this repo. Configure here.