Skip to content

fix(benchmarks): raise-with-string, fd leak, unused arg, and typo (refs #4335)#4337

Open
Anai-Guo wants to merge 5 commits intopytorch:mainfrom
Anai-Guo:fix/benchmarks-import-and-bugs
Open

fix(benchmarks): raise-with-string, fd leak, unused arg, and typo (refs #4335)#4337
Anai-Guo wants to merge 5 commits intopytorch:mainfrom
Anai-Guo:fix/benchmarks-import-and-bugs

Conversation

@Anai-Guo
Copy link
Copy Markdown
Contributor

Fixes part of #4335 — broken imports and bugs in benchmarks/ directory.

This PR addresses the bugs that can be fixed without touching benchmarks whose underlying APIs were removed (benchmark_uintx.py, benchmark_rowwise_scaled_linear_sparse_cutlass.py, benchmark_sparse_conversion_cutlass.py); those need a maintainer call on whether to delete the files or rewrite against the post-AQT API, so I left them out.

Fixes

1. benchmark_hqq.pyraise with string argument (Python 3 invalid)

# before
if int(triton.__version__.split(".")[0]) < 3:
    raise "triton >= 3.0.0 is required to run this test"
except ImportError:
    raise "triton and hqq required to run this benchmark"

In Python 3, raise <str> raises TypeError: exceptions must derive from BaseException, which masks the intended message. Replaced with raise RuntimeError(...) (and from e chained on the ImportError path).

2. intmm.py:102 — leaked file descriptor

shapes = list(csv.reader(open(file_path, "r")))[1:]

Wrapped in a with block.

3. benchmark_gpu_sparsity.py:31 — unused x parameter, callers passing strings

def benchmark_model_with_warmup(func, x, N_WARMUP=3):
    benchmark_model(func, N_WARMUP, device_type="cuda")
    return benchmark_model(func, 10, device_type="cuda")

x is never used inside the body. Callers were passing strings like "dense.json.gz" as the second positional argument — likely a remnant of an earlier signature that took a profile-output filename. The strings were never written anywhere. Dropped the parameter and updated all four call sites.

4. benchmark_aq.py:47 — typo deprecated_tenosr_subclass

Renamed to deprecated_tensor_subclass (consistent within the function, so behavior unchanged — readability only).

Not touched

  • benchmark_uintx.py: torchao.prototype.uintx and uintx_affine_weight_only have been removed; no drop-in replacement exists per the issue. Needs a maintainer decision on whether to delete or rewrite.
  • benchmark_rowwise_scaled_linear_sparse_cutlass.py / benchmark_sparse_conversion_cutlass.py: import _float8_cutlass_quant/_float8_cutlass_quant_sparse which were removed when AQT was deleted. The current API is in torchao/quantization/quantize_/workflows/float8/sparse_2x4_cutlass_float8_tensor.py, but porting the benchmarks to it is non-trivial — happy to do it in a follow-up if there's interest.
  • The output-collision item (both sparse-cutlass benchmarks writing to the same CSV name) is moot until those files are rewritten.

Verification

python -m py_compile benchmarks/benchmark_aq.py
python -m py_compile benchmarks/benchmark_hqq.py
python -m py_compile benchmarks/intmm.py
python -m py_compile benchmarks/benchmark_gpu_sparsity.py

All four pass.

๐Ÿค– Generated with Claude Code

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 26, 2026

๐Ÿ”— Helpful Links

๐Ÿงช See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4337

Note: Links to docs will display an error until the docs builds have been completed.

โ— 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 26, 2026

Hi @Anai-Guo!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant