[float8] read dim from kwargs in Float8Tensor aten.split handler - #4429
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4429
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below:
|
Fixes pytorch#4430. The `aten.split.Tensor` handler on `Float8Tensor` (added in pytorch#3334) unpacks three positionals from `args`: tensor, split_size_or_sections, dim = args That works for `Tensor.chunk(n, dim=d)` and other call sites where the dispatcher hands `dim` over in `args`. It does NOT work for the free-function form `torch.chunk(t, n, dim=d)`, which reaches the handler with `args = (tensor, split_size_or_sections)` and `dim` in `kwargs`: ValueError: not enough values to unpack (expected 3, got 2) This breaks every `fully_shard(module)` call where the module's weights have been quantized via `quantize_(model, Float8DynamicActivationFloat8WeightConfig(...))`, because FSDP2's `_chunk_with_empty` is implemented as: chunks = list(torch.chunk(tensor, num_chunks, dim=dim)) Fix --- Read `dim` from either positional or keyword form, matching the `aten.split.Tensor` schema `(Tensor self, SymInt split_size, int dim=0)`. Test Plan --------- Adds `test_chunk_via_torch_chunk_with_dim_kwarg` alongside the existing `test_chunk`. The existing test only exercises `Tensor.chunk(...)` (the vLLM Llama 4 path from pytorch#3334), so the free-function call form was not covered. The new test calls `torch.chunk(t, n, dim=dim)` explicitly. pytest test/quantization/quantize_/workflows/float8/test_float8_tensor.py \ -s -x -k 'chunk'
f0f0802 to
9a21bc8
Compare
|
@claude review this PR |
|
Claude finished @vkuzo's task in 52s —— View job PR Review: [float8] read
|
Fixes #4430.
Summary
The
aten.split.Tensorhandler onFloat8Tensor(added in #3334) unpacks three positionals fromargs:That works for
Tensor.chunk(n, dim=d)and other call sites where the dispatcher handsdimover inargs. It does not work for the free-function formtorch.chunk(t, n, dim=d), which reaches the handler withargs = (tensor, split_size_or_sections)anddiminkwargs:This breaks every
fully_shard(module)call where the module's weights have been quantized viaquantize_(model, Float8DynamicActivationFloat8WeightConfig(...)), because FSDP2's_chunk_with_emptyis implemented as:Minimal reproducer
Originally hit under FSDP2 + 4-card NPU (
torchao_npu); same code path triggers on CUDA + FSDP2 too.Fix
Read
dimfrom either positional or keyword form, matching theaten.split.Tensorschema(Tensor self, SymInt split_size, int dim=0):Test Plan
Adds
test_chunk_via_torch_chunk_with_dim_kwargnext to the existingtest_chunk. The existing test only exercisesTensor.chunk(...)(the vLLM Llama 4 path from #3334), which is why this regression was not caught. The new test callstorch.chunk(t, n, dim=dim)explicitly:pytest test/quantization/quantize_/workflows/float8/test_float8_tensor.py -s -x -k 'chunk'The new test fails before the handler fix with
ValueError: not enough values to unpack (expected 3, got 2), and passes after.Related
Float8Tensoraten.split.Tensorhandler crashes ontorch.chunk(t, n, dim=<kwarg>)(breaks FSDP2fully_shard) #4430torch.chunkto float8tensor #3334 (LLaMA 4 MoE weight loading via vLLM).