Skip to content

Handle dynamic non-string type-name metadata - #146

Open
Essoz wants to merge 6 commits into
codex/torchscript-builtin-identityfrom
codex/dynamic-type-names
Open

Essoz wants to merge 6 commits into
codex/torchscript-builtin-identityfrom
codex/dynamic-type-names

Conversation

@Essoz

@Essoz Essoz commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

PyTorch's dynamic OpsWrapper returns functions for __qualname__ and __name__. TrainCheck rejected the former but accepted the latter, then failed its string assertion; this blocked fresh MNIST trace collection before the first training step.

Validate the fallback __name__ as a nonempty string before using it. Preserve valid name precedence and the existing reported __class__ fallback, and avoid truth-testing non-string metadata. This is a one-line production change stacked on #143.

Validation:

  • The same seven-test suite against the exact parent function and candidate changes from 4 passed / 3 failed to 7 passed / 0 failed, including the actual PyTorch OpsWrapper.
  • 23 combined type-name, tracing-integrity, and TorchScript tests pass on Python 3.10.16 / PyTorch 2.2.2 / macOS arm64; pinned Ruff, Mypy, Black, and isort hooks pass.
  • Matching Linux runtime (Python 3.11.4 / PyTorch 2.16.0.dev20261012+cpu): all seven type-name regressions pass within 29 integration tests, plus 11 checker-observer tests. The exact signed utility source and runtime module path were verified; the real OpsWrapper returns the expected name in both modes.
  • A fresh 10-step MNIST collection succeeds with the exact narrow fix in the explicitly composed tracing/TorchScript/cache/state-fix stack, with unchanged source hashes and model-state shapes. The earlier broader-workaround pilot is retained separately. This is composed-stack compatibility evidence, with no fix-isolated training or performance claim.
  • Independent review found no blocker.

Reproduction and compact before/after evidence: docs/experiments/dynamic-type-names.md and docs/experiments/dynamic-type-names-results.json.

Engineering hardening

Typed typename(object, bool) -> str and its test helpers, preserving the fallback guards and final assertions (b64023b). Two added negative tests verify invalid fallback metadata still fails and metadata access exceptions propagate. All 37 combined tracing/TorchScript/type-name tests pass, as do pinned hooks and stronger scoped Mypy 1.9 checks. utils.py retains its one pre-existing stronger-check stub diagnostic; no new ignores, casts, or relaxed assertions were introduced.

Separately composed updated production sources pass 140 affected Linux regression tests, whole-source Mypy (77 files), Ruff, and isort. Whole-source Black still reports three unchanged legacy files, down from six in the original base; changed-file hooks pass. Strict checks are scoped and do not establish repository-wide strict typing. Historical performance numbers above retain their original measured revisions; this hardening pass does not re-estimate them.

This branch has not been deployed

No deployments
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