Skip to content

Fix 0-d new_zeros/new_ones in remove_const_ops; run test_quant_LLM without the KV cache - #296

Merged
shivadbhavsar merged 2 commits into
ROCm:masterfrom
amarbarosys:fix/remove-const-ops-0d-size
Oct 28, 2026
Merged

shivadbhavsar merged 2 commits into
ROCm:masterfrom
amarbarosys:fix/remove-const-ops-0d-size

Conversation

@amarbarosys

@amarbarosys amarbarosys commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

tests/dynamo/quantization/test_quantized_models_dynamo.py::test_quant_LLM fails on master with transformers 5.x (measured on 5.16.1; CI pins 4.41.2, which I have not run), and fixing that exposes a compile crash in the backend that any graph with a 0-d new_zeros/new_ones hits, whatever the transformers version. No existing issue covers either.

Technical Details

  • remove_const_ops (_remove_new_const_ops) built the constant with torch.zeros(*size) / torch.ones(*size). For a 0-d result (size == []) that is a call without a size: TypeError: ones() missing 1 required positional arguments: "size". It now passes the size list as is.
  • test_quant_LLM: under transformers 5.x, GPT2Model returns a DynamicCache in its output when use_cache is on (its default), which torch.export cannot flatten, so the test failed in export_for_quantization before reaching MIGraphX. The test only compares last_hidden_state, so it now loads the model with use_cache=False.

Test Plan

  • tests/dynamo/passes/test_remove_const_ops.py: new 0-d new_zeros and new_ones cases.
  • test_quant_LLM on master vs this branch.
  • Full tests/dynamo.
    Setup: RX 7900 XTX (gfx1100), ROCm 7.2, torch 2.13, transformers 5.16.1, MIGraphX develop (a3b5db6).

Test Result

  • New 0-d cases: fail on master with the TypeError, pass here (9 passed).
  • test_quant_LLM: 2 failed on master (DynamicCache), 2 passed here.
  • tests/dynamo: 378 passed, 10 skipped.

Submission Checklist

_remove_new_const_ops built the constant with torch.zeros(*size) /
torch.ones(*size). For a 0-d result (size == []) that is a call with no
size at all and raises "missing 1 required positional arguments: size",
so any graph with a 0-d new_zeros/new_ones fails to compile. GPT2 under
transformers 5.x produces one. Pass the size list as is.

test_remove_const_ops gains 0-d new_zeros and new_ones cases: both fail
with the TypeError before this change and pass after (9 passed).
With transformers 5.x, GPT2Model returns a DynamicCache in its output when
use_cache is on (the default). torch.export cannot flatten that type, so
the test failed in export_for_quantization before reaching MIGraphX. The
test only compares last_hidden_state, so load the model with
use_cache=False.

Both parametrizations fail on master with the DynamicCache error and pass
with this change and the remove_const_ops fix (gfx1100, torch 2.13,
transformers 5.16.1). tests/dynamo: 378 passed, 10 skipped.
@shivadbhavsar
shivadbhavsar merged commit 562bfe7 into ROCm:master Oct 28, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants