PyTorch Frontend Review
Apply alongside frontend guidance to PyTorch translators, passes, decoders, and conversion tests.
Capture and dispatch
- Identify the actual capture path: scripted/traced
TorchScript,
torch.export.ExportedProgram, ortorch.compilethrough the FX decoder. Inspect the captured graph and configured decomposition/functionalization; sharing a decoder does not imply identical operators, metadata, or mutations. Do not assume decompositions run or require them just to hide missing support. - Trace dispatch through the operation table
and translation session.
aten::addandaten.add.Tensormay use shared translators or FX overrides. Check overload schemas, keyword arguments, omitted defaults,None, and inlined scalars/lists before sharing logic across capture paths or versions. context.input_is_none(i)checks bounds and returnstruewheni >= context.get_input_size(), as well as for an explicitNone. It can guard optional inputs without a separate range check; do not flag calls beyond the input count as out-of-bounds access.- Distinguish capture specialization from conversion defects. Do not turn symbolic shape calculations into example-input constants, or reorder user inputs, parameters, buffers, and flattened container outputs.
Type alignment
- Reuse promotion helpers
(
align_eltwise_input_types,get_inputs_with_promoted_types,is_python_scalar_input,align_output_types) and wrappers where their rules apply. - Distinguish Python scalars, zero-dimensional tensors, and other tensors.
Promotion depends on numeric category and operand kind, not just stored
dtype. Preserve decoder
PyScalarinformation and pass correct scalar flags. - Align operands before arithmetic; casting afterward cannot repair overflow, truncation, or wrong division. Check result types separately, especially comparisons, reductions, integer true division, and explicit/default dtype. Decoder output metadata may be dynamic, so it cannot replace promotion logic.
- Apply operator-specific rules: in-place destination dtype, allowed
out=casts, and scalar arguments such asalphadiffer from ordinary promotion. When dtype decoding changes, keep Python mappings and C++ ScalarType interpretation consistent. Use shared frontend rules for 64-bit tradeoffs.
Mutation and aliases
Follow NodeContext::mutate_input and session alias handling, not only the
returned value: later base/view uses must see updates, while values computed
before mutation remain unchanged. Check in-place return aliases and out=
destinations when affected. Preserve view/copy distinctions: non-contiguous
reshape may copy, and *_copy variants must not gain aliases merely because
values match. Use the captured graph and decoder alias contract as evidence.
Regression coverage
Confirm the actual mode in the
layer-test harness:
PYTORCH_TRACING_MODE=EXPORT selects export, TORCHFX selects the compile
backend, and the ordinary path uses TorchScript scripting/tracing options.
Check affected paths when shared logic receives different schemas or metadata;
do not demand unsupported capture modes.
Verify the expected operator/overload survives capture and decomposition. For the changed rule, check mixed dtype/scalar kinds, multiple permitted shapes, or observable mutation of bases/views. Assert converted types for dtype changes; numerical agreement alone does not establish type fidelity.