Files
Laith Sakka 6e804dfe63 [symbolic shapes] Remove deprecated size-oblivious APIs (#202008) (#202008)
Summary:

X-link: https://github.com/meta-pytorch/torchrec/pull/4950

Remove the deprecated guard_size_oblivious Python and C++ APIs, bindings and Dynamo handling together with ShapeEnv size-like bookkeeping, range clamping and evaluation flags. Simplify ShapeGuard to expression and source location. Preserve backed_size_oblivious, stride policy and local Min/Max simplification. Keep the deprecated _check_is_size helper and registration for unchanged FBGEMM callers. Rebase onto master at 9b7ccc84fd21, where the scheduler/caller migrations have landed, and remove the unused SizeVarAllocator.evaluate_expr size_oblivious parameter.

Preserve range refinement and u0 -> 1 replacement. Omit the Dynamo tensor-size guard only when its original placeholder is a single unbacked symbol replaced by 0/1. Remove the skip_unbacked_specialization converter parameter and the redundant track_symint early return; retain normal constraint/translation-validation handling. Do not add unbacked guard fallbacks when runtime assertions are explicitly disabled. Share the size-only elision helper between normal guard construction and guard serialization, preserving None before SymInt provenance is lost during serialization. Stride handling and other metadata are unchanged. Tighten the existing unbacked reshape regression to expect the first range assertion, u0 <= 1, instead of either the old equality or new range message.

At the FB package-importer boundary, migrate only known legacy source in torchrec.pt2.checks and torchrec.sparse.jagged_tensor. Replace the archived pt2_guard_size_oblivious helper with false/true variants preserving its scripting/non-PT2 early return. Accept both known is_pt2_compiling and older is_torchdynamo_compiling wrapper patterns without changing the archived compilation predicate or pt2_check_size_nonzero. Repoint legacy direct and wrapped numel() comparisons: == 0 uses guard_or_false, != 0 and > 0 use guard_or_true, with the corresponding pt2_ wrappers. Continue supporting the direct KeyedJaggedTensor.dist_init case and unused obsolete imports. Use validated AST references and descending UTF-8 byte-span edits, preserving unrelated source bytes; do not unparse whole modules. Other modules, conflicting/aliased imports and unsupported uses remain unchanged rather than receiving guessed semantics. No blanket alias, legacy stub, custom unsupported-error policy or new migration tests are added. Older runtimes that still provide the legacy API remain unchanged. No public deprecated API is restored and no stored model archive is overwritten.

Add focused ShapeEnv zero/one range and constant-replacement tests, plus an eager tensor-guard serialization round-trip after refinement to one. Compare live and reloaded guard acceptance, preserving checks on unrelated static dimensions.

AI Assistance: Prepared with Devmate following the user-approved cleanup and FB-only archive-migration plan.

Test Plan:
Latest legacy-wrapper update: validated the actual checks and jagged source at the cited historical revision b68e2cebce7e75b34a36f9ecf6ff546b3a1a3d8c. Confirmed the previous matcher left the older checks source unchanged; the new matcher migrates both modules and they compile. Both generated wrappers preserve the exact archived early-return source bytes, and every other checks function, including pt2_check_size_nonzero, is byte-for-byte unchanged. Revalidated the previously supported real ADS 576285072 archived checks source; unknown compilation predicates and non-whitelisted modules remain unchanged. Idempotence, Black and syntax checks passed. Only the FB migration helper changed; no build target, core, live TorchRec, archive or test-file edits. Mandatory validation ran and returned unrelated LoopsIR workspace diagnostics. This is source-transformation validation, not a full real-archive load/PT2 retrace result.

Earlier update-specific evidence follows:

Latest test-only update: extended test_unbacked_markings_round_trip and added test_unbacked_size_range_refines_to_zero_one / test_unbacked_size_replaced_by_zero_one in both mirrors. The serialization case checks live/reloaded guards accept a differently sized marked tensor after refinement to one, while a changed static dimension is rejected. The ShapeEnv cases assert range [0, 1], constant zero/one replacements and singleton ranges. No production code or build targets changed. Syntax checks and mirror identity passed; Black passed on the serialization files and requested only an existing unrelated docstring change in the dynamic-shapes files, also present in the base commit, left untouched. Mandatory validation ran and returned diagnostics in the unrelated LoopsIR checkout. A focused opt Buck invocation for the three methods timed out after 240 seconds without completed test results; runtime behavior remains unverified.

The following paragraphs retain historical update-specific evidence:

V7.1 archived-wrapper extension: real ADS 576285072 module-factory/inference and MRS 930792918 module-factory checks/jagged source pairs transform and compile successfully. Validated the false/true guard split, unchanged archived PT2 early-return AST, idempotence and non-whitelisted-module passthrough. Revalidated the actual model 562591695.6 predictor.tp direct recat.numel() > 0 source: import and call become guard_or_true, license header preserved. Non-executing pickletools inspection of predictor.tp and predictor.local.tp found no legacy guard identifiers in their pickle operations. Scoped Black, arc f and syntax checks passed. Mandatory validation ran and returned existing diagnostics in unedited core files, not a clean workspace result. No tests were added and no runtime suites were run. A full real-archive from_torch_package load and PT2/AOTI retrace remain unverified: no usable warm loader executable was located, and no cold build was started. Only the FB migration helper changed; live TorchRec, core mirrors, loaders and build targets are unchanged. Earlier test results below remain historical.

Historical updates and evidence retained below:

Latest user-requested update: rebased D125627656 onto refreshed master 9b7ccc84fd21 without conflicts. Scheduler keyword callers are already migrated on this base. Removed only the size_oblivious parameter from SizeVarAllocator.evaluate_expr in both mirrors; fallback forwarding and unrelated _compute_stride APIs are unchanged. Syntax checks passed. Both sizevars mirrors and the guards, symbolic_shapes and unbacked-test mirror pairs match byte-for-byte. No tests were added or run. Mandatory validation was invoked and reported unrelated diagnostics outside this checkout; Black requested only an existing unrelated conditional-expression formatting change, left untouched.

Latest review fixes: normal TENSOR_MATCH construction and serialize_guards now use the same size-only conversion/elision helper before pickling. Original metadata is copied, not mutated; strides and other fields retain the previous conversion. The existing test_reshape_indexer_unbacked_total_size_fixes_value assertion now expects only u0 <= 1. Both fbcode/xplat guard and test pairs match byte-for-byte. No tests were added or run. Validation was invoked and reported unrelated/pre-existing diagnostics. The Black check requested only existing union-annotation formatting outside the edited sections, which was left untouched.

Latest review update: restored the pre-existing live TorchRec old-runtime import fallback. The live checks module is now unchanged from the base. The single known archived direct-call patch remains. No tests were run and no loader performance benchmark is claimed.

Latest scope update: the loader now patches only the direct import and the exact recat_cond assignment in torchrec.sparse.jagged_tensor.KeyedJaggedTensor.dist_init. It preserves all other source bytes. The earlier generalized checks-module migration, pt2 wrapper conversion and custom unsupported errors are no longer present. Earlier archived-wrapper validation below is historical and does not claim those variants are supported by the narrowed implementation. Scoped formatting/autodeps checks passed; no tests were run.

Review update: removed the newly added TorchRec legacy-migration tests and their build target at the user's request. Existing compatibility tests remain unchanged. The real archive-loader migration remains intact. Removed the redundant direct //caffe2:torch dependency; the PyPI Torch alias still supplies the same implementation. Scoped formatting and loader autodeps checks passed. No runtime tests were rerun; the earlier test run was stopped at the user's request. Validation reported only unrelated pre-existing diagnostics in the separate PyTorch LoopsIR checkout.

The historical test results below predate this deletion and do not claim current coverage from the removed tests.

Final focused warm opt CPU run: 21 passed, 0 failed (5 archive migration checks, 2 existing unbacked reshape regressions, 14 existing specialization/runtime-assert checks): https://www.internalfb.com/intern/testinfra/testrun/12384899187836959. Coverage includes unresolved unbacked empty/nonempty bias, >0 nonempty predicates, concrete behavior, older-runtime passthrough, source inspection, state/global pickle roundtrip, unsupported predicates and attribute/alias rejection, and public legacy API absence. Both actual MTIA archives' checks/jagged source pairs transform and compile successfully; IG Notes maps 1 empty + 3 nonempty calls, MRS PYMK maps 1 empty + 2 nonempty calls. This is source-transformation validation, not a full model runtime pass.

Scoped arc f and validate_changes passed; core fbcode/xplat mirrors match. The affected MTIA IG Notes/MRS PYMK, CPU-lowering and SlimDSNN model-test batch timed out after 900 seconds in native/Triton build work without completed model-test results; those suites remain unverified. No singleton min/max=1 tests were reintroduced, and the PendingUnbackedSymbolNotFound follow-up remains outside this change.

Earlier warm-base versions were validated with CPU dynamic shapes (331 passed), scheduler (118 passed), Dynamo misc (2765 passed), Dynamo unspec (178 passed), FBGEMM suites (139 passed), and c10 core (93 passed), plus _C_impl_cpu/_libtorch builds. These historical counts do not claim a rerun after the current review changes. Source-only XLA compatibility sweep at revision 1e110020e found no removed-API references or deleted-method overrides; XLA was not rebuilt.

Reviewed By: ezyang

Differential Revision: D125627656

Pull Request resolved: https://github.com/pytorch/pytorch/pull/202008
Approved by: https://github.com/ezyang
2026-10-28 04:10:20 +00:00
..
2026-07-11 01:28:16 +00:00
2025-06-11 23:00:52 +00:00
2025-04-16 21:35:19 +00:00
2026-06-04 18:06:46 +00:00
2025-08-14 01:49:35 +00:00