Skip to content

refactor(dynamo): make _requires_output_allocator a pure predicate - #4369

Merged
cehongwang merged 1 commit into
mainfrom
fix-data-dependent-fallback-predicate
Jun 29, 2026
Merged

cehongwang merged 1 commit into
mainfrom
fix-data-dependent-fallback-predicate

Conversation

@cehongwang

Copy link
Copy Markdown
Collaborator

Description

Follow-up cleanup to #4355.

The _requires_output_allocator helper in the partitioner previously folded the fallback_data_dependent_ops setting into its return value: it returned False for a node that genuinely required a TRT output allocator whenever the setting was disabled (the default). That made the name misleading at the call sites — _requires_output_allocator(node) == False did not actually mean "this node does not require an output allocator," it usually meant "the setting is off."

This flips the semantics so the helper is a pure predicate: it reports whether the converter selected for a node needs a TRT output allocator (data-dependent output shape, e.g. nonzero or boolean index.Tensor), independent of any setting. The fallback_data_dependent_ops gate moves to the two operator-support call sites (TorchTensorRTOperatorSupport.is_node_supported and OpSupportTester.is_node_supported).

The setting is still checked first at the call sites, preserving the short-circuit that skips the converter-registry lookup in the default (off) case. Behavior is unchanged end to end.

Details

  • _global_partitioner.py: _requires_output_allocator no longer reads compilation_settings; the caller now guards with settings is not None and settings.fallback_data_dependent_ops and self._requires_output_allocator(node).
  • _adjacency_partitioner.py: same gate added at the OpSupportTester call site.

Tests

tests/py/dynamo/models/test_fallback_data_dependent_ops.py:

  • Added test_requires_output_allocator_is_setting_independent: the pure predicate returns True for nonzero regardless of the setting.
  • Updated test_output_allocator_node_falls_back_only_when_enabled: now drives is_node_supported(...) and asserts the node stays on TensorRT (True) when the flag is off and falls back (False) when it is on — testing the real partitioner decision rather than the helper in isolation.

Type of change

  • Refactor / code-quality improvement (non-breaking, no behavior change)

Checklist

  • My code follows the style guidelines of this project (isort + black, passed via pre-commit)
  • I have added/updated tests
  • Commit is signed off (DCO)

The _requires_output_allocator helper previously folded the
fallback_data_dependent_ops setting into its return value, so it returned
False for a node that genuinely required an output allocator whenever the
setting was disabled. That made the name misleading at the call sites.

Flip the semantics so the helper purely reports whether the converter
selected for a node needs a TRT output allocator (data-dependent output
shape), and move the fallback_data_dependent_ops gate to the two operator
support call sites. The setting is still checked first, preserving the
short-circuit that skips the registry lookup in the default (off) case.

Behavior is unchanged end to end. Update the unit test to assert the pure
predicate is setting-independent and to verify the setting-gated fallback
decision through is_node_supported.

Signed-off-by: cehongwang <wangcehong@gmail.com>
@meta-cla meta-cla Bot added the cla signed label Jun 26, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Jun 26, 2026

@narendasan narendasan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cehongwang
cehongwang merged commit 7eec04f into main Jun 29, 2026
110 of 128 checks passed
cehongwang added a commit that referenced this pull request Jul 21, 2026
…4369)

Signed-off-by: cehongwang <wangcehong@gmail.com>
(cherry picked from commit 7eec04f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants