Skip to content

Commit c5bf380

Browse files
authored
Fix stale Int4Tensor assertions in gemma4_31b CUDA pipeline tests (pytorch#20230)
Packing converts Int4Tensor weights to CudaCoalescedInt4Tensor because the CUDA int4 kernel is registered only on the coalesced type, which is intentionally not a subclass of Int4Tensor. Update test_int4_weights_preserved and test_load_converts_weights to assert CudaCoalescedInt4Tensor.
1 parent 01f80e7 commit c5bf380

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

examples/models/gemma4_31b/tests/test_cuda_pipeline.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,13 @@ def _forward(self):
190190
return self.model(tok, pos, temp)
191191

192192
def test_int4_weights_preserved(self):
193-
"""Packing passes Int4Tensor through without conversion."""
194-
from torchao.quantization.quantize_.workflows.int4.int4_tensor import Int4Tensor
193+
"""Packing converts Int4Tensor to CudaCoalescedInt4Tensor."""
194+
from executorch.backends.cuda.coalesced_int4_tensor import (
195+
CudaCoalescedInt4Tensor,
196+
)
195197

196198
w = self.model.layers[0].mlp.gate_proj.weight.data
197-
self.assertIsInstance(w, Int4Tensor)
199+
self.assertIsInstance(w, CudaCoalescedInt4Tensor)
198200

199201
def test_inference_produces_valid_output(self):
200202
out = self._forward()
@@ -243,14 +245,19 @@ def _load(self, tmp):
243245
return load_gguf_model(path, backend="cuda", config=GGUF_CONFIG)
244246

245247
def test_load_converts_weights(self):
246-
"""GGUF -> CUDA: Q4_K -> Int4Tensor, Q6_K -> IntxUnpacked, embedding bf16."""
248+
"""GGUF -> CUDA: Q4_K -> CudaCoalescedInt4Tensor, Q6_K -> IntxUnpacked,
249+
embedding bf16."""
250+
from executorch.backends.cuda.coalesced_int4_tensor import (
251+
CudaCoalescedInt4Tensor,
252+
)
247253
from torchao.quantization import IntxUnpackedToInt8Tensor
248-
from torchao.quantization.quantize_.workflows.int4.int4_tensor import Int4Tensor
249254

250255
with tempfile.TemporaryDirectory() as tmp:
251256
model, _ = self._load(tmp)
252257

253-
self.assertIsInstance(model.layers[0].self_attn.q_proj.weight.data, Int4Tensor)
258+
self.assertIsInstance(
259+
model.layers[0].self_attn.q_proj.weight.data, CudaCoalescedInt4Tensor
260+
)
254261
self.assertIsInstance(
255262
model.layers[0].mlp.down_proj.weight.data, IntxUnpackedToInt8Tensor
256263
)

0 commit comments

Comments
 (0)