Skip to content

Remove deprecated public TorchScript APIs + tests - #203621

Closed
janeyx99 wants to merge 25 commits into
gh/janeyx99/437/basefrom
gh/janeyx99/437/head
Closed

janeyx99 wants to merge 25 commits into
gh/janeyx99/437/basefrom
gh/janeyx99/437/head

Conversation

@janeyx99

@janeyx99 janeyx99 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Summary (human written only)

Remove deprecated public TorchScript APIs and their tests; preserve needed internal source through build-time overrides, with no copied tests.

What is getting deleted?

Already deprecated public torch.jit APIs:

script, script_method, interface, trace, trace_module, load, save, freeze, optimize_for_inference, set_fusion_strategy, fork, wait.

Also removed the APIs that are transitively also deprecated:

  • Public Python torch.load acceptance of TorchScript ZIP/module archives, in either weights_only mode. Ordinary tensor/state-dict checkpoints remain supported.
  • Deprecated-API-only JIT/fuser/mobile suites and test assets, scripted benchmark modes and their dead helpers, and stale discovery/CI/ownership references.
  • The private NNAPI Python host-conversion path and its specific C++ preprocessing callback. Native NNAPI execution and generic backend dispatch remain.
  • Obsolete TorchScript-only documentation and the unused supported_ops doc-generation module.

And the tests and benchmarks associated with the above APIs.

This is not wholesale deletion of torch/csrc/jit. Supported public ScriptModule/CompilationUnit, native C++ serialization, package and flatbuffer features, MKLDNN conversion and public AD dependencies retain the implementation they need. The JVP helper remains unchanged: its deletion broke ordinary gradient-JVPs, and the author asked to keep it. These would need to be deprecated first!

What is the impact?

  1. Cleaner code!!!!! Retired frontend tests, fixtures, benchmark modes and dead references are deleted! Gone!
  2. Less CI test work. Median CI test work removed: 145.0 min per PR pull run; 487.5 min per main pull+trunk push, for a total of at least 632min per PR!
AI-generated measurement details (provisional; not final-green)

Fresh baseline medians: 145.0 aggregate test-minutes per PR pull run (n=10) and 487.5 per SHA-paired main pull + trunk push (n=6). Separate main medians: 231.0 pull / 256.9 trunk (n=10 each).

The PR sample contains 6,547 distinct executed removed cases, median 4,415/run. Retiring the entire CPP parity driver contributes a median 18.2 PR test-minutes/run. Target determination varies; these are recorded test-work estimates, not wall-clock savings.

Baseline workflows: November 5 noon–November 6 noon UTC, with facts before November 6 20:00 UTC; latest job attempts and non-skipped recorded durations. Scope is pinned to e2090877 / tree efbb8f01, not final-green. Build/setup, skips, retained coverage and all temporary twelve-model CPU/GPU TorchBench and BERT-smoke deferrals receive no credit.

Full report (internal) · Reproducible queries, CSVs and source audit (internal).

  1. Side effect: We also learned that despite our best intentions, we did not fully deprecate TorchScript in 2.10 and 2.11. There are still many other use cases and cross cutting functionality we need to slap a FutureWarning to, which this PR has started to track in the deprecation issue!

Disclaimer(s) + Things We Need To Deprecate

C++ archive compatibility: Python torch.load no longer accepts TorchScript module archives, including archives produced by C++ torch::save for ordinary tensors, tensor lists, modules, or optimizers. This behavior was already deprecated and is now fully removed. Native C++ torch::save/torch::load remains unchanged. For C++→Python tensor/value interchange, use torch::pickle_save with Python torch.load. Existing C++ archive files are not automatically migrated.

  • To unblock this retirement, BERT_pytorch and eleven Detectron2 models are temporarily excluded from CPU and GPU Inductor TorchBench; their BERT-only smoke subcases are deferred too. Migration/re-enablement is tracked in Migrate some torchbench models away from torchscript + add them back to inductor bench #203757.

  • C++ module-parity transport and the two custom-backend fixture sites have concrete representation boundaries. Ordinary modules/state-dict archives do not satisfy the existing native module reader; ExportedProgram/FX inputs do not satisfy the custom backend's _c/jit::Module interface. Those cases are retained deliberately, not because their value is unknown.

  • The ScriptModule RPC return-value/archive transport cut is held pending an explicit scope decision: the retained public producer works, and removing the reducer causes a verified serialization failure. The old transport itself uses deprecated archive frontend helpers. Other obsolete RPC fixture/docs cleanup is independent.

  • The AOTI TorchBind fixture and native CUDA-stream fixture still need matching native artifacts/platform validation before a supported fixture replacement can be accepted. No fake objects, unverified skips or weakened tolerances were substituted.

  • The broader scripted RemoteModule, TensorBoard and legacy ONNX cuts remain follow-up work; their complete package/isolation/runtime validation is still pending. The utility follow-up is now published: obsolete JIT testing helpers and their solely-dependent benchmark provider are removed, the old fuser comparison launcher is deleted, and explicit retired varlen-LSTM script options reject rather than silently running eager code. No half-cut API is described as finished.

  • BC Lint still flags scriptAndSave/Test from the deleted Android generator and jit_step from the deleted example path. No path exclusions, dead aliases or rule suppression have been added; this remains a documented compatibility-classification gate.

  • Remote/TensorBoard validation remains a capability gate. A genuine standalone package and safe isolation were established; after-package source selection passed, but existing sampled telemetry needed runtime inventory. A same-worker read-only inventory input was then checked without exposing identifying values, yet the baseline timed out in offline configuration retries. Afterward no after-package or TensorBoard run was launched. The prepared broader cuts remain out of this published checkpoint; no unisolated fallback, logger/sampling bypass, or production access was used to turn the gate green.

  • Follow-up deprecation of functorch.compile.ts_compile is tracked in [deprecation] functorch.compile.ts_compile #203804, attached under ☂️ Deprecations and frozen components: when they started, and when the code is removed #201298. This retirement does not remove it or claim that a new warning has shipped.

How did I deal with internal?

We migrate the deleted files into the fb folder:

  • fb/torch/jit/__init__.py → installed torch/jit/__init__.py
  • fb/torch/serialization.py → installed torch/serialization.py

The original names and relative layout are preserved under (fbcode|xplat)/caffe2/fb/torch/. BUCK/ovrsource selects these sources at build time; internal callers keep canonical imports. Nothing else is copied.

AI has checked the JIT initializer is byte-identical to the pinned pre-removal source. Serialization preserves the original implementation/warning/loader with only the formatter's placement of a TypeIs import changed.

Test plan

  • CI should be green publicly and internally before merging. Current checks are still being monitored; this is an expectation, not an assertion that all jobs passed.
  • Relevant failures were reproduced locally before fixes and checked afterward. ARM performance uses CI under the author's explicit local-validation exception.
  • The internal BUCK metadata failure reproduced before cleanup and the same owner query passed afterward; the orphan test target was removed rather than restored. Native NNAPI builds/links passed before and after the host-preprocessing cut; baseline host startup and Android execution remain separate unverified runtime gates.
  • Fresh canonical internal validation passed six core contracts before and six after the frozen copy/layout change. The original OSS-specific shared assertions reproduced 14 failures internally; the corrected three existing tests plus a separate identity check passed without skips or mocked package flags.
  • Public/ internal model-selection checks preserve unrelated arguments and selections; the CPU/GPU extension and its effective-backend edge were locally checked. This does not substitute for GPU model accuracy/performance CI.
  • The public hook-fixture migration passed all 17 builders and generated all 15 native fixture archives with matching behavior. The full C++ executable is not claimed passed.
  • The stale upgrader provider reproduced a real missing-source error locally; its dead target/wrapper closure is now removed, while retained codegen manifest/package checks pass. The dependency spelling resolves to the same configured canonical Torch provider.
  • Dynamo no longer registers the deleted JIT-only assertion context. Its exact context lookup failed locally before and passed after; real compile/FX probes passed on both sides and are not presented as reproducing all wrapped-CI failures. Per the owner's review direction, the EmbeddingBag_sparse C++ parity registration and its C++-only constructor metadata are removed; the ordinary NN fixture and other parity cases remain. The incidental PGO change and added regression are reverted, restoring both PGO files byte-for-byte to their pre-fix contents. This is intentional coverage retirement, not a compiler fix or a claim that the retirement caused the original PGO failure.
  • For this review update, five one-off source/registration checks passed: exact PGO-file restoration, removal of only the selected parity registration, unchanged ordinary NN fixture metadata, deletion of only ConcatGraphOptBench and its registration, and comment-only Dynamo cleanup. Public lintrunner and internal Arc/mirror hooks passed. These are source/registration checks, not a full native C++ parity execution. Human review and CI are still required; no merge or landing is authorized.

How to best review

  1. Review the bottom timm PR separately: it contains only the dependency pin.
  2. In this PR, start with torch/jit/__init__.py and torch/serialization.py: verify exact exports removed and format-specific Python loading behavior.
  3. Group deleted suites with their fixtures/helper/provider closure; inspect mixed-test edits for preserved independent eager/public coverage rather than private TorchScript parity.
  4. Review surviving library callers, RPC/NNAPI boundaries, and the narrowly scoped CPU/GPU TorchBench deferral. Compare normal, performance, dashboard and exporter/backend controls.
  5. Review D129970553 separately for canonical internal source selection, original-layout copies, no test copies, and the source-identity/runtime evidence. Source adaptation is not inferred from a matching filename.
  6. Check the posted Export/Dynamo questions and explicitly documented validation gaps rather than treating an unrelated green job as their resolution.

Links

Part of #201298

Dependency: #203783

Deferred CPU TorchBench migrations: #203757

Differential Revision: https://www.internalfb.com/diff/D130430904

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01 @gujinghui @PenghuiCheng @jianyuh @min-jean-cho @yanbing-j @Guobing-Chen @Xia-Weiwen @snadampal @albanD @voznesenskym @penguinwu @EikanWang @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @azahed98

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

⚪ AUTOMATED REVIEW - Skipped, PR too large to review:

This PR is over the automated review's size limit, so it was not reviewed.

Reviewed commit: 7543dc7

Review run

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/203621

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

❌ 1 New Failure, 2 Unclassified Failures

As of commit 7543dc7 with merge base 29e8991 (image):

🟡 GREEN LIGHT - PR was reverted - re-landing requires human review:

Green Light will not review this PR again, on this or any later commit; re-landing it needs a human approval.

NEW FAILURE - The following job has failed:

  • BC Lint / bc_linter (gh)

    AI verdict: AI verdict: related

    BC Lint fails because the suspect PR, "Remove deprecated public TorchScript APIs + tests", deletes public Python functions and classes. The linter flags exactly those deletions (scriptAndSave, Test, jit_step), and every recent trunk run of BC Lint is green.

    Full reasoning on HUD →

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

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

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/mps Run MPS tests (subset of trunk) ciflow/torchtitan Run TorchTitan integration tests module: cpu CPU specific problem (e.g., perf, algorithm) module: dynamo module: mkldnn Related to Intel IDEEP or oneDNN (a.k.a. mkldnn) integration release notes: quantization release notes category release notes: releng release notes category labels Nov 5, 2026
[ghstack-poisoned]
janeyx99 added a commit that referenced this pull request Nov 5, 2026
… support retained)

## Linked issue or supporting maintainer

Part of #201298

Differential Revision: https://www.internalfb.com/diff/D129970553

## Summary (human written only)

> yea can you make a draft PR linked to diff (a codev PR i guess) to show me what's happening?

> Since there was already an older deprecation warning on that behavior, we can remove the functionality!

## Agent details

### AI-generated summary

This visibility draft removes deprecated public TorchScript Python aliases and 163 dedicated public test/asset files. It now also rejects TorchScript archives passed to public torch.load, for either weights_only mode. Ordinary tensor/state-dict checkpoints remain supported. Migration guidance points to exporting the original model or using an older version to load an existing legacy archive.

Internal canonical JIT/RPC APIs, the original full serialization module, and original archive-loading tests are retained in the internal diff through excluded fb/ providers; those files are not included here. Shared native serialization/compiler infrastructure remains for surviving or unwarned consumers.

This is not a completed removal rollout. The public preview is adapted to the captured public base and must be reconciled with the final CodeSync export before landing the internal diff. Do not merge it independently on GitHub.

### AI-generated validation status

Not ready to merge or land. The initial full internal CPU run recorded 3909 TPX passes, 77 failures and 374 skips. Of those failures, 41 reproduced on the unchanged base, 34 were relocation resource-adjacency defects, and 2 stochastic quantization failures remain unclassified. All 34 relocation failures passed after repairing coherent source/fixture staging. No original test or golden values were changed to hide a failure.

For expanded archive retirement, all 11 targeted internal serialization methods passed, including original legacy-archive acceptance. The exported public source passed both archive-rejection cases and 10 ordinary checkpoint/sharing methods. The complete 19-method public compatibility suite also passed after correcting its old archive expectations. These public runs reused real unchanged native libraries and are limited Python/source-profile evidence, not a full rebuilt native candidate.

Full CodeSync translation was checked to contain 309 intended public paths, all 163 public deletions, and zero private source/destination/copy/rename headers. The internal original source preimages and source mappings were reviewed independently. Two review findings—a stale public compatibility test and stale documentation—were fixed.

Normal-configuration Dynamo and remote GPU/LLVM validation are running on a separate worker against the hash-verified v2 snapshot. GPU/mobile/ARVR, final export-to-diff reconciliation, and the remaining baseline/quantization exceptions remain gates.

### AI-generated test plan

The public patch passed syntax and whitespace checks. Scoped spin lint passed for the public modified files; ownership metadata was validated against the committed tree after removing dead test patterns and adding the compatibility test to its existing ownership group.

```sh
spin fixlint -- torch/serialization.py test/test_serialization.py test/test_torchscript_compatibility.py docs/source/notes/cpu_threading_torchscript_inference.md
lintrunner -a OWNERSHIP.yaml CODEOWNERS
git diff HEAD --check
```

CI remains deferred for this changing review-only draft and must be enabled before merge gating. Prepared with an AI assistant under the owner's direction and explicit approval to publish draft updates. No land or merge is authorized.

ghstack-source-id: 5a31a60
Pull-Request: #203621
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 5, 2026
[ghstack-poisoned]
janeyx99 added a commit that referenced this pull request Nov 5, 2026
… support retained)

## Linked issue or supporting maintainer

Part of #201298

Differential Revision: https://www.internalfb.com/diff/D129970553

## Summary (human written only)

> yea can you make a draft PR linked to diff (a codev PR i guess) to show me what's happening?

> Since there was already an older deprecation warning on that behavior, we can remove the functionality!

## Agent details

### AI-generated summary

This visibility draft removes deprecated public TorchScript Python aliases and 163 dedicated public test/asset files. It also rejects TorchScript archives passed to public torch.load, for either weights_only mode. Ordinary tensor/state-dict checkpoints remain supported. Migration guidance points to exporting the original model or using an older version to load an existing legacy archive.

Internal canonical JIT/RPC APIs, the original full serialization module, and original archive-loading tests are retained in the internal diff through excluded fb/ providers; those files are not included here. Shared native serialization/compiler infrastructure remains for surviving or unwarned consumers.

This is not a completed removal rollout. The public preview is adapted to the captured public base and must be reconciled with the final CodeSync export before landing the internal diff. Do not merge it independently on GitHub.

### AI-generated validation status

Not ready to merge or land. The initial full internal CPU run recorded 3909 TPX passes, 77 failures and 374 skips. All 34 relocation resource-adjacency failures passed after repairing coherent source/fixture staging. The remaining 43 failures reproduced on the unchanged base, leaving zero unclassified cases. Focused QNNPACK reproduction confirmed a Hypothesis differing_executors harness error; the original leaky-ReLU inner test reproduced the logged numerical mismatch across four engines. The latter replays saved decimal inputs, not claimed original seed or raw-bit identity. No assertions or tolerances were changed to hide failures.

For expanded archive retirement, all 11 targeted internal serialization methods passed, including original legacy-archive acceptance. The exported public source passed both archive-rejection cases and 10 ordinary checkpoint/sharing methods. The complete 19-method public compatibility suite passed after correcting its old archive expectations; the subsequently retained native CallStack regression passed separately. These public runs reused real native libraries and are limited Python/source-profile evidence, not a full rebuilt native candidate.

Final V4 CodeSync translation contains 313 public paths, all 163 public deletions, 23 real binary records, and zero private/copy/rename/placeholder headers. Independently reviewed direct official export and baseline-plus-patch trees match across all 22538 paths, blob hashes, and modes. Existing 408 retained source files remain byte-identical; four new copies have reviewed import-order/docstring-only formatting and passing runtime checks. The earlier archive-test/documentation/Windows-fixture findings were fixed. The external PR review's five caller/documentation defects are addressed: generated code and surviving fixtures use existing private implementations, the retained archive driver uses its existing loader, the obsolete compiler example is removed, and a retired scripting-only compiler-flag subcheck is deleted. Focused CallStack lifetime and FileCheck rejection/boundary regressions remain for still-supported native utilities.

Separate exact-v2 normal opt/NVIDIA validation completed: 18164 Dynamo methods produced 17438 passes, 726 upstream skips, zero failures/fatals/timeouts. All 120 failed GPU/LLVM method identities/statuses reproduced on the exact unchanged base. Most generated NNC cases return early because they are CPU-only; they are not GPU-operator coverage. These runs precede later review fixes. Subsequent actual compiled-native instantiator execution passed all three methods, including the corrected generated scripted RemoteModule template. Broader downstream/mobile/ARVR coverage, public CI, release-warning eligibility, and final GitHub-to-export reconciliation remain gates.

### AI-generated test plan

The public patch passed syntax and whitespace checks. Scoped spin lint passed for the modified files. Actual public-source/native-library checks passed for generated Callgrind load source, the archive driver with an eager .orig checkpoint, the quantization save/load fixture, one cross-thread CallStack test, and all 16 FileCheck tests. These are source-profile and native utility checks, not a complete native rebuild or Valgrind performance run. Three actual compiled-native generated-template methods passed separately. Ownership metadata was checked against the committed tree.

```sh
spin fixlint -- torch/serialization.py test/test_serialization.py test/test_torchscript_compatibility.py docs/source/notes/cpu_threading_torchscript_inference.md
lintrunner -a OWNERSHIP.yaml CODEOWNERS
git diff HEAD --check
```

CI remains deferred for this changing review-only draft and must be enabled before merge gating. Prepared with an AI assistant under the owner's direction. No land or merge is authorized.

ghstack-source-id: 812e563
Pull-Request: #203621
@janeyx99
janeyx99 marked this pull request as ready for review November 5, 2026 21:27
@janeyx99
janeyx99 marked this pull request as draft November 5, 2026 21:27
@janeyx99

janeyx99 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@claude we are removing deprecated APIs + their tests. can you go over this and ensure:

  • we are not deleting any public apis/functionality by accident. call these out.
  • more minor, whether you see more that we can delete that we missed. this can go in a followup but i'm just curious.

@claude

claude Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Claude finished @janeyx99's task in 2m 51s —— View job


Nothing outside the targeted list gets deleted from torch.jit by accident, but several remaining public APIs can no longer be used, and the PR misses callers that will break CI (benchmarks/fastrnns, the RPC JIT test helpers, the public-API allowlist).

Details

Summary

This PR removes 12 names from the public torch.jit namespace: script, script_method, interface, trace, trace_module, load, save, freeze, optimize_for_inference, set_fusion_strategy, fork and wait. It also makes torch.load reject TorchScript archives and deletes about 62k lines of TorchScript tests.

I checked these points directly:

  • Deprecation status: every removed name emitted a runtime FutureWarning or DeprecationWarning at base (_script.py:367,1495,1648, _trace.py:1008, _serialization.py:91,180, _freeze.py:107,232, _fuser.py:170, _async.py:105,126). The old torch.load path called torch.jit.load, so it showed that function's FutureWarning.
  • Rest of torch.jit: no other names were removed from torch.jit/__init__.py. script_if_tracing, CompilationUnit, ScriptModule, Attribute, ignore, export and annotate still work.
  • Deleted eager test cases: the cases removed from test_distributions, test_transforms, test_linalg, test_binary_ufuncs, test_indexing, test_shape_ops, test_nn, test_transformers, test_utils, test_lazy_modules and test_futures only cover TorchScript. I found no eager-mode coverage lost.

1. Public functionality this effectively removes (please confirm each is intended)

Removed from the public namespace on purpose, with user-visible effects:

  • No public way to load TorchScript is left, but saving still works. ScriptModule.save(), save_to_buffer(), torch.jit.CompilationUnit and torch.jit.save_jit_module_to_flatbuffer are all still public, and the new test even builds an archive with CompilationUnit(...).save_to_buffer(). torch.load now raises (torch/serialization.py:1568) and torch.jit.load is gone. Oddly, torch.jit.jit_module_from_flatbuffer is still a public loader for the flatbuffer format. Either finish the job (deprecate the save paths and jit_module_from_flatbuffer), or say clearly in the release notes that users can still write archives they can't read back. Anything that goes through torch.load inherits the new error, for example torch.hub.load_state_dict_from_url pointed at a TorchScript file.
  • torch.jit.fork / torch.jit.wait inside scripted source no longer compile. torch/csrc/jit/python/python_sugared_value.cpp:1207 drops the fork special form. wait was resolved through Python attribute lookup, so it is gone too. Models that are still scripted internally and call torch.jit.fork(...) in their bodies will now fail to compile, not just eager callers. Only torch.jit._fork and torch.jit._wait still work. If this is intended, it belongs in the release notes.

Still public, but there is no longer a public way to create their input (a ScriptModule, an interface, or a traced module). They are not deleted, but users can't do anything with them. Most have no runtime deprecation warning, so they should get one, or the PR should say why they stay:

  • torch.utils.mobile_optimizer.optimize_for_mobile
  • torch.utils.bundled_inputs.*
  • torch.ao.quantization.quantize_jit / prepare_jit / convert_jit
  • torch.jit.export_opnames
  • torch.jit.run_frozen_optimizations
  • torch.jit.fuser / optimized_execution / strict_fusion / last_executed_optimized_graph
  • torch.backends._nnapi
  • RemoteModule(_module_interface_cls=...): its docs still say "decorate with @torch.jit.interface" (torch/distributed/nn/api/remote_module.py:184,567, torch/distributed/nn/jit/instantiator.py:19,123).

Things that break because of this PR and are not handled:

  • CI breakage: benchmarks/fastrnns/{factory,custom_lstms,scratch}.py use torch.jit.script / @jit.script_method. custom_lstms.py fails at class definition, which happens at import. .ci/pytorch/test.sh:2369-2371 runs pytest benchmarks/fastrnns/test_bench.py from test_benchmarks, which is called at test.sh:2867.
  • Dead files that can't be imported: torch/testing/_internal/distributed/rpc/jit/{rpc_test,rpc_test_faulty,dist_autograd_test}.py have about 70 module-level @torch.jit.script / @torch.jit.interface uses. The PR unhooked them from rpc_utils.py but left the files, and test/test_public_bindings.py:350-352 still lists them. Delete all three files and the allowlist entries.
  • Stale allowlist: test/allowlist_for_publicAPI.json:331-353, the "torch.jit" entry, still lists all 12 removed names.
  • Dead helper: torch/testing/_internal/common_quantization.py:501 get_script_module still calls torch.jit.trace / script and has no callers left. Remove it.
  • Benchmarks broken at runtime or import:
    • benchmarks/dynamo/common.py:1351,1499,1503 (try_script, --torchscript-jit-trace)
    • benchmarks/instruction_counts/core/expand.py:189,240, which writes torch.jit.load / script into generated source
    • benchmarks/operator_benchmark/{benchmark_pytorch.py:181, common/tests/jit_forward_test.py, pt_extension/cpp_extension_test.py}
    • benchmarks/framework_overhead_benchmark/pt_wrapper_module.py, benchmarks/fuser/run_benchmarks.py, benchmarks/tensorexpr/benchmark.py
    • benchmarks/profiler_benchmark/profiler_bench.py, benchmarks/record_function_benchmark/record_function_bench.py
    • benchmarks/dynamo/microbenchmarks/{microbench,operatorbench}.py
  • Also broken:
    • functorch/benchmarks/{operator_authoring.py:39 (fails at import), pointwise_scorecard.py, cse.py} and functorch/examples/compilation/linear_train.py
    • android/pytorch_android/generate_test_torchscripts.py, which fails at class definition
  • Messages that point users at removed APIs:
    • torch/serialization.py:1891 still says "did you mean to use torch.jit.load()?".
    • The private implementations' deprecation warnings still name the removed public symbols, e.g. "torch.jit.script is deprecated" (same lines as the deprecation list in the Summary).
    • .. testcode:: examples in torch/jit/__init__.py:133,219 and in the _script.py, _trace.py, _serialization.py, _freeze.py and _async.py docstrings still use @torch.jit.script and friends, so docs doctests will fail.
    • docs/source/user_guide/torch_compiler/export.md:94,100 has {func} cross-references to torch.jit.script / torch.jit.trace that now dangle.

Smaller issues in the diff:

  • test/test_transformers.py: the comment "brazenly adapted from test_transformerencoderlayer_src_mask..." is left dangling after the test it described was deleted, with stray blank lines around it.
  • test/test_ops_jit.py: instead of deleting the traced-variant checks, the PR adds a new _trace_graph_fixture helper and quietly limits trace-based shape and autodiff checks to float32. That is a coverage change outside the PR's stated scope. Consider deleting the traced path, or the file (see below).
  • test/test_torchscript_compatibility.py:
    • test_legacy_archive_compatibility behaves completely differently under IS_FBCODE. As a result the OSS file tests fbcode-only behavior that OSS CI never runs.
    • test_shared_future and test_thread_safe_error_stacks don't test TorchScript compatibility; they look like tests salvaged from deleted files.

2. More that could be deleted (follow-up)

  • Stale references to deleted test files:
    • test/run_test.py: lines 219-220 (test_jit_legacy, test_jit_cuda_fuser), 239 (test_jit), 314 (test_jit_disabled), 2085 (test_jit) and 2119 (the "jit" Windows blocklist entry). The --jit option (lines 1592 and 1925) now only matches leftovers.
    • tools/testing/discover_tests.py:90-92 and tools/testing/modulefinder_determinator.py:33-35
    • tools/linter/adapters/test_linter_allowlist.json:525-603,737-743 and tools/linter/adapters/pytorch_labels.json:648 (test-config/jit_legacy)
    • .lintrunner.toml:367,1128,1420-1430, pyproject.toml:722-733 (ruff per-file ignores for test/jit/** and test/test_jit.py)
    • .github/merge_rules.yaml:311 and .github/labeler.yml:62 (test/test_jit_llga_fuser.py)
  • Orphaned helper: torch/testing/_internal/test_module/{__init__,future_div,no_future_div}.py is referenced only by .lintrunner.toml.
  • Remaining TorchScript-only test suites you could delete if the scope widens:
    • test/test_ops_jit.py, and with it common_jit.py and jit_metaprogramming_utils.py
    • test/quantization/jit/
    • test/test_tensorexpr*.py, test/test_static_runtime.py, test/test_mobile_optimizer.py
    • test/jit_hooks/ and test/cpp/jit/tests_setup.py, which need matching .ci/pytorch/{test,macos-test,build}.sh edits
  • Leftover deprecated API surface:
    • torch.jit.ignore(drop_on_export=True) / ignore(True) (_jit_internal.py:887-901) and the no-op optimize= argument (_script.py:1148, _trace.py:1016) already warn at runtime, so they can go now.
    • annotate, isinstance, script_if_tracing, export_opnames, enable_onednn_fusion / onednn_fusion_enabled and strict_fusion only have a docstring deprecation note, so they need a runtime warning first.
  • Docs: torch/csrc/jit/OVERVIEW.md (including line 1461, which points at test_jit.py), torch/csrc/jit/JIT-AUTOCAST.md, functorch/COMPILE_README.md:62-64 and tools/coverage_plugins_package (a coverage plugin for functions compiled with torch.jit.script).
  • Leave alone: .ci/docker/requirements-ci.txt mentions these tests only in comments, and any edit there triggers a Docker image rebuild.

Recommendation

Request Changes. The fastrnns CI breakage, the dead RPC JIT test helpers plus their test_public_bindings entries, and the stale allowlist_for_publicAPI.json entries should be fixed in this PR. For the public APIs whose inputs can no longer be created, and for the asymmetric removal of loading while saving still works, decide explicitly and record it in the release notes.

@janeyx99 janeyx99 changed the title [no-ci] Retire deprecated public TorchScript APIs and tests (internal support retained) Retire deprecated public TorchScript APIs and tests (internal support retained) Nov 5, 2026
janeyx99 added a commit that referenced this pull request Nov 5, 2026
… retained)

## Linked issue or supporting maintainer

Part of #201298

Differential Revision: https://www.internalfb.com/diff/D129970553

## Summary (human written only)

> yea can you make a draft PR linked to diff (a codev PR i guess) to show me what's happening?

> Since there was already an older deprecation warning on that behavior, we can remove the functionality!

## Agent details

### AI-generated summary

This visibility draft removes deprecated public TorchScript Python aliases and 163 dedicated public test/asset files. It also rejects TorchScript archives passed to public torch.load, for either weights_only mode. Ordinary tensor/state-dict checkpoints remain supported. Migration guidance points to exporting the original model or using an older version to load an existing legacy archive.

Internal canonical JIT/RPC APIs, the original full serialization module, and original archive-loading tests are retained in the internal diff through excluded fb/ providers; those files are not included here. Shared native serialization/compiler infrastructure remains for surviving or unwarned consumers.

This is not a completed removal rollout. The public preview is adapted to the captured public base and must be reconciled with the final CodeSync export before landing the internal diff. Do not merge it independently on GitHub.

### AI-generated validation status

Not ready to merge or land. The initial full internal CPU run recorded 3909 TPX passes, 77 failures and 374 skips. All 34 relocation resource-adjacency failures passed after repairing coherent source/fixture staging. The remaining 43 failures reproduced on the unchanged base, leaving zero unclassified cases. Focused QNNPACK reproduction confirmed a Hypothesis differing_executors harness error; the original leaky-ReLU inner test reproduced the logged numerical mismatch across four engines. The latter replays saved decimal inputs, not claimed original seed or raw-bit identity. No assertions or tolerances were changed to hide failures.

For expanded archive retirement, all 11 targeted internal serialization methods passed, including original legacy-archive acceptance. The exported public source passed both archive-rejection cases and 10 ordinary checkpoint/sharing methods. The complete 19-method public compatibility suite passed after correcting its old archive expectations; the subsequently retained native CallStack regression passed separately. These public runs reused real native libraries and are limited Python/source-profile evidence, not a full rebuilt native candidate.

Final V4 CodeSync translation contains 313 public paths, all 163 public deletions, 23 real binary records, and zero private/copy/rename/placeholder headers. Independently reviewed direct official export and baseline-plus-patch trees match across all 22538 paths, blob hashes, and modes. Existing 408 retained source files remain byte-identical; four new copies have reviewed import-order/docstring-only formatting and passing runtime checks. The earlier archive-test/documentation/Windows-fixture findings were fixed. The external PR review's five caller/documentation defects are addressed: generated code and surviving fixtures use existing private implementations, the retained archive driver uses its existing loader, the obsolete compiler example is removed, and a retired scripting-only compiler-flag subcheck is deleted. Focused CallStack lifetime and FileCheck rejection/boundary regressions remain for still-supported native utilities.

Separate exact-v2 normal opt/NVIDIA validation completed: 18164 Dynamo methods produced 17438 passes, 726 upstream skips, zero failures/fatals/timeouts. All 120 failed GPU/LLVM method identities/statuses reproduced on the exact unchanged base. Most generated NNC cases return early because they are CPU-only; they are not GPU-operator coverage. These runs precede later review fixes. Subsequent actual compiled-native instantiator execution passed all three methods, including the corrected generated scripted RemoteModule template. Broader downstream/mobile/ARVR coverage, public CI, release-warning eligibility, and final GitHub-to-export reconciliation remain gates.

### AI-generated test plan

The public patch passed syntax and whitespace checks. Scoped spin lint passed for the modified files. Actual public-source/native-library checks passed for generated Callgrind load source, the archive driver with an eager .orig checkpoint, the quantization save/load fixture, one cross-thread CallStack test, and all 16 FileCheck tests. These are source-profile and native utility checks, not a complete native rebuild or Valgrind performance run. Three actual compiled-native generated-template methods passed separately. Ownership metadata was checked against the committed tree.

```sh
spin fixlint -- torch/serialization.py test/test_serialization.py test/test_torchscript_compatibility.py docs/source/notes/cpu_threading_torchscript_inference.md
lintrunner -a OWNERSHIP.yaml CODEOWNERS
git diff HEAD --check
```

CI is enabled for this review draft; its required checks must pass before merge gating. Prepared with an AI assistant under the owner's direction. No land or merge is authorized.

ghstack-source-id: 812e563
Pull-Request: #203621
[ghstack-poisoned]
@janeyx99 janeyx99 changed the title Retire deprecated public TorchScript APIs and tests (internal support retained) [WIP] Retire deprecated public TorchScript APIs; retain internal implementations only Nov 6, 2026
janeyx99 added a commit that referenced this pull request Nov 6, 2026
…ementations only

## Linked issue or supporting maintainer

Part of #201298

Differential Revision: https://www.internalfb.com/diff/D129970553

## Summary (human written only)

> yea can you make a draft PR linked to diff (a codev PR i guess) to show me what's happening?

> Since there was already an older deprecation warning on that behavior, we can remove the functionality!

## Agent details

### AI-generated summary

Implementation-only second attempt under the owner's updated scope. Retire the twelve already-warned public TorchScript aliases and public torch.load acceptance of TorchScript ZIP archives. Keep ordinary checkpoints and concrete supported public consumer coverage. Delete the obsolete CPU threading TorchScript page; migration/rationale belongs in the release/change summary.

All 480 task-added internal legacy-test/helper/fixture/golden/provider files from V4/R1/R2 are removed, along with their retention routing. Only necessary canonical JIT and serialization implementation overlays remain. Pre-existing internal-only test files are not copied or deleted. The internal diff and public deletion preview are separate review surfaces and require final CodeSync reconciliation.

Public fastrnns CI now uses native/CUDNN/eager variants, not privately re-scripted retired variants. Public JIT OpInfo parity and the conditional IS_FBCODE xfail workaround are removed. Real mobile optimizer/lint/bundled-input coverage remains, including focused XNNPACK Conv1d optimizer returned graph/numerics without private rewrite/serde assertions. Scoped global deletion groups are continuing in independent scratch worktrees; this is not complete all-test assurance.

### AI-generated validation status

WIP, not ready to merge or land. Historical frozen R2 public F1-wheel profile: 23 collected, 18 passes, 5 existing prerequisite skips (four missing XNNPACK, one missing torchvision), zero failures/XPASS. Historical internal R2: four actual method passes (three instantiator cases and async multi-fork), one copied-JSON packaging failure; other records are mains/listings. That test-retention architecture has now been removed, not claimed fixed by those results. These runs do not certify the current implementation-only source.

Normal Spin setup/version/type-stub generation was explicitly approved and ran. Scoped fixlint and precommit lintrunner applied formatting/import fixes. The taxonomy checker uses committed HEAD paths: before commit it reported 169 now-deleted paths, while unchanged checker analysis of the actual staged 22,522 paths has zero uncovered/stale/duplicate/ineffective/order/group/owner errors. The normal taxonomy check is rerun after commit. No linter, hook, test, ownership scope or security bypass was used.

The all-test audit and native dependency contracts remain incomplete; 418 candidate paths and 27 extra dependency paths are under review. Known exact follow-ups and supported-build XNNPACK validation are pending and will be additional authorized iterations. No global audit or passing-CI gate is implied by this visibility draft. CI stays enabled. No merge or landing is authorized.

### AI-generated test plan

```sh
spin lint -- <changed surviving files>
spin fixlint -- <changed surviving files>
lintrunner -a <changed surviving files>
git diff --cached --check
python scripts/codeowners/check_taxonomy.py
```

No newly copied internal tests, fixtures, goldens or test-only providers remain. Public and internal binary-complete patches and exact source/base hashes are banked for owner review.

ghstack-source-id: 1bed8ef
Pull-Request: #203621
[ghstack-poisoned]
janeyx99 added a commit that referenced this pull request Nov 6, 2026
…ementations only

## Linked issue or supporting maintainer

Part of #201298

Differential Revision: https://www.internalfb.com/diff/D129970553

## Summary (human written only)

> yea can you make a draft PR linked to diff (a codev PR i guess) to show me what's happening?

> Since there was already an older deprecation warning on that behavior, we can remove the functionality!

## Agent details

### AI-generated summary

Implementation-only second attempt under the owner's updated scope. Retire the twelve already-warned public TorchScript aliases and public torch.load acceptance of TorchScript ZIP archives. Keep ordinary checkpoints and concrete supported public consumer coverage. Delete the obsolete CPU threading TorchScript page; migration/rationale belongs in the release/change summary.

All 480 task-added internal legacy-test/helper/fixture/golden/provider files from V4/R1/R2 are removed, along with their retention routing. The additional two compatibility suites and two hook-fixture helpers outside that prefix inventory are now removed as well; the pre-existing hook utility remains unchanged at its original path for its verified public C++ Module consumer. Only necessary canonical JIT and serialization implementation overlays remain. Pre-existing internal-only test files are not copied or deleted. The internal diff and public deletion preview are separate review surfaces and require final CodeSync reconciliation.

Public fastrnns CI now uses native/CUDNN/eager variants, not privately re-scripted retired variants. Public JIT OpInfo parity and the conditional IS_FBCODE xfail workaround are removed. Real mobile optimizer/lint/bundled-input coverage remains, including focused XNNPACK Conv1d optimizer returned graph/numerics without private rewrite/serde assertions. The additional 20-file verified legacy ONNX/converter/package deletion group is integrated; modern export, public package archives and eager assertions remain. Complete source audit attribution is not runtime assurance, which continues on independent immutable inputs.

### AI-generated validation status

WIP, not ready to merge or land. Historical frozen R2 public F1-wheel profile: 23 collected, 18 passes, 5 existing prerequisite skips (four missing XNNPACK, one missing torchvision), zero failures/XPASS. Historical internal R2: four actual method passes (three instantiator cases and async multi-fork), one copied-JSON packaging failure; other records are mains/listings. That test-retention architecture has now been removed, not claimed fixed by those results. These runs do not certify the current implementation-only source.

Normal Spin setup/version/type-stub generation was explicitly approved and ran. Scoped fixlint and precommit lintrunner applied formatting/import fixes. The taxonomy checker uses committed HEAD paths: before commit it reported 169 now-deleted paths, while unchanged checker analysis of the actual staged 22,522 paths has zero uncovered/stale/duplicate/ineffective/order/group/owner errors. The normal taxonomy check is rerun after commit. No linter, hook, test, ownership scope or security bypass was used.

The all-test audit and native dependency contracts remain incomplete; 418 candidate paths and 27 extra dependency paths are under review. Known exact follow-ups and supported-build XNNPACK validation are pending and will be additional authorized iterations. No global audit or passing-CI gate is implied by this visibility draft. CI stays enabled. No merge or landing is authorized.

### AI-generated test plan

```sh
spin lint -- <changed surviving files>
spin fixlint -- <changed surviving files>
lintrunner -a <changed surviving files>
git diff --cached --check
python scripts/codeowners/check_taxonomy.py
```

No newly copied internal tests, fixtures, goldens or test-only providers remain. Public and internal binary-complete patches and exact source/base hashes are banked for owner review.

ghstack-source-id: 62d4e7e
Pull-Request: #203621
[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ci-refresh-hf-cache ciflow/docker ciflow/inductor ciflow/mps Run MPS tests (subset of trunk) ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request GL/superseded GreenLight review is superseded by changes in progress PR is being worked on by the author, until the automated review accepts it Merged module: cpu CPU specific problem (e.g., perf, algorithm) module: dynamo module: inductor module: mkldnn Related to Intel IDEEP or oneDNN (a.k.a. mkldnn) integration release notes: quantization release notes category release notes: releng release notes category Reverted skip-pr-sanity-checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants