pytorch - 💡(How to fix) Fix [Inductor][Bucketing] Hinted unbacked SymInts should remain symbolic in bucket traces

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Inductor collective bucketing does not handle unbacked SymInts with explicit optimization hints consistently.

Bucketing uses tensor metadata for two different purposes:

  1. The traced bucket merge graph needs symbolic tensor shapes to remain symbolic.
  2. Bucket sizing and foreach grouping need concrete integers only to choose an optimization policy.

When a bucket input has a hinted unbacked chunk size such as u0 // 2, the policy path needs to evaluate a concrete estimate from the hint, but the traced graph must keep u0 // 2 symbolic in numel, split sizes, reshapes, and output shapes. Existing code paths can force a guarding hint or specialize symbolic metadata, which either fails on the unbacked symbol or loses the symbolic shape.

Error Message

The bucket trace can fail when policy code tries to force a guarding concrete value for an unbacked SymInt, or it can incorrectly use concrete hints in semantic graph shapes. Unhinted unbacked symbolic sizes should fail with a clear bucketing error, but explicitly hinted unbacked sizes should be accepted for policy decisions.

Root Cause

Inductor collective bucketing does not handle unbacked SymInts with explicit optimization hints consistently.

Bucketing uses tensor metadata for two different purposes:

  1. The traced bucket merge graph needs symbolic tensor shapes to remain symbolic.
  2. Bucket sizing and foreach grouping need concrete integers only to choose an optimization policy.

When a bucket input has a hinted unbacked chunk size such as u0 // 2, the policy path needs to evaluate a concrete estimate from the hint, but the traced graph must keep u0 // 2 symbolic in numel, split sizes, reshapes, and output shapes. Existing code paths can force a guarding hint or specialize symbolic metadata, which either fails on the unbacked symbol or loses the symbolic shape.

Code Example

import torch
from torch._C import FileCheck
from torch._inductor.fx_passes.bucketing import (
    _trace as bucketing_trace,
    all_gather_merge_fn_to_trace_custom_ops,
)
from torch._subclasses import FakeTensorMode
from torch.fx.experimental.symbolic_shapes import ShapeEnv


fake_mode = FakeTensorMode(allow_non_fake_inputs=True, shape_env=ShapeEnv())
with fake_mode:
    u = fake_mode.shape_env.create_unbacked_symint()
    torch._dynamo.override_optimization_hint(u, 8)
    x = torch.empty(u // 2, 4)
    y = torch.empty(u // 2, 4)

gm = bucketing_trace(
    lambda a, b: all_gather_merge_fn_to_trace_custom_ops(
        [a, b],
        "0",
        2,
        torch.float32,
        [torch.float32, torch.float32],
        0,
    ),
    (x, y),
)

FileCheck().check("sym_numel").check("_pre_bucket_all_gather").run(gm.code)
print(gm.code)
RAW_BUFFERClick to expand / collapse

Summary

Inductor collective bucketing does not handle unbacked SymInts with explicit optimization hints consistently.

Bucketing uses tensor metadata for two different purposes:

  1. The traced bucket merge graph needs symbolic tensor shapes to remain symbolic.
  2. Bucket sizing and foreach grouping need concrete integers only to choose an optimization policy.

When a bucket input has a hinted unbacked chunk size such as u0 // 2, the policy path needs to evaluate a concrete estimate from the hint, but the traced graph must keep u0 // 2 symbolic in numel, split sizes, reshapes, and output shapes. Existing code paths can force a guarding hint or specialize symbolic metadata, which either fails on the unbacked symbol or loses the symbolic shape.

Reproducer

import torch
from torch._C import FileCheck
from torch._inductor.fx_passes.bucketing import (
    _trace as bucketing_trace,
    all_gather_merge_fn_to_trace_custom_ops,
)
from torch._subclasses import FakeTensorMode
from torch.fx.experimental.symbolic_shapes import ShapeEnv


fake_mode = FakeTensorMode(allow_non_fake_inputs=True, shape_env=ShapeEnv())
with fake_mode:
    u = fake_mode.shape_env.create_unbacked_symint()
    torch._dynamo.override_optimization_hint(u, 8)
    x = torch.empty(u // 2, 4)
    y = torch.empty(u // 2, 4)

gm = bucketing_trace(
    lambda a, b: all_gather_merge_fn_to_trace_custom_ops(
        [a, b],
        "0",
        2,
        torch.float32,
        [torch.float32, torch.float32],
        0,
    ),
    (x, y),
)

FileCheck().check("sym_numel").check("_pre_bucket_all_gather").run(gm.code)
print(gm.code)

Expected behavior

The bucket trace should succeed. Policy-only decisions, such as bucket byte accounting and foreach grouping, may use explicit optimization hints. The traced merge graph should still contain symbolic size operations such as sym_numel and symbolic split/reshape sizes.

Actual behavior

The bucket trace can fail when policy code tries to force a guarding concrete value for an unbacked SymInt, or it can incorrectly use concrete hints in semantic graph shapes. Unhinted unbacked symbolic sizes should fail with a clear bucketing error, but explicitly hinted unbacked sizes should be accepted for policy decisions.

Notes

This needs a local bucketing contract: hints may choose bucket/group policy, but they must not replace symbolic tensor sizes in the graph being traced.

cc @chauhang @penguinwu @ezyang @bobrenjc93 @aditvenk @laithsakka @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The bucket trace should succeed. Policy-only decisions, such as bucket byte accounting and foreach grouping, may use explicit optimization hints. The traced merge graph should still contain symbolic size operations such as sym_numel and symbolic split/reshape sizes.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - 💡(How to fix) Fix [Inductor][Bucketing] Hinted unbacked SymInts should remain symbolic in bucket traces