Skip to content

Handle scalar outputs in parameter MAC calculations - #431

Open
linjiaye929 wants to merge 1 commit into
TylerYep:mainfrom
linjiaye929:fix/scalar-output-macs-20261107
Open

linjiaye929 wants to merge 1 commit into
TylerYep:mainfrom
linjiaye929:fix/scalar-output-macs-20261107

Conversation

@linjiaye929

Copy link
Copy Markdown

A scalar nn.PReLU forward succeeds, but summary(model, input_data=torch.tensor(-1.0)) fails in calculate_macs() because the generic weight/bias fallback indexes the empty output shape.

Use the product of the first output dimension instead. For scalar outputs the empty product is one; every non-scalar multiplier stays unchanged. Add seven public-API cases covering scalar PReLU through both input routes, vector/batched controls, and a scalar affine reduction, including parameter and memory accounting.

Validation on Linux, Python 3.12.14, PyTorch 2.11.0+cpu:

  • New regressions against the unchanged parent: 3 failed, 4 passed. All seven pass after the fix.
  • Standard snapshot suite with torchvision 0.26.0+cpu and transformers 5.22.2: 116 passed, 11 skipped, 2 deselected. No snapshots were changed and --no-output was not used.
  • Full mypy: no issues in 21 source files. Ruff 0.17.2 lint/format and patch whitespace checks pass.

The two deselected tests download pretrained weights (test_eval_order_doesnt_matter and test_flan_t5_small). Skips cover ten CUDA tests and the existing nondeterministic Faster R-CNN test. Python 3.13/3.14, coverage collection, and the pre-commit wrapper were not run. Earlier runs under unsupported PyTorch 2.8 had the same 50 storage-size snapshot errors on both baseline and fix; all disappear under PyTorch 2.11.

This is separate from #390's scalar input generation and #37's scalar shape handling. Prepared with AI assistance; no human review is claimed.

@linjiaye929
linjiaye929 marked this pull request as ready for review November 7, 2026 19:16
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.

1 participant