Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions core/runtime/TRTEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,12 +579,23 @@ bool TRTEngine::bind_nccl_comm() {
// auto-resolve when there is exactly one — if there are several (TP+DP,
// Megatron 4-D parallelism, etc.) we cannot know which group this engine
// belongs to and the caller must pin it explicitly.
// PyTorch >= 2.13 throws c10::Error (instead of returning nullptr) when
// the requested group name doesn't exist. try_resolve normalises this to a
// nullptr return so the scan loop stays exception-free.
auto try_resolve = [](const std::string& name) -> c10::intrusive_ptr<c10d::ProcessGroup> {
try {
return c10d::resolve_process_group(name);
} catch (const c10::Error&) {
return nullptr;
}
};
std::vector<std::string> nccl_groups;
for (int i = 0; i < 20; ++i) {
auto candidate = std::to_string(i);
auto probe = c10d::resolve_process_group(candidate);
if (probe != nullptr && probe->getBackendType() == c10d::ProcessGroup::BackendType::NCCL) {
nccl_groups.push_back(candidate);
auto pg = try_resolve(std::to_string(i));
if (!pg)
break;
if (pg->getBackendType() == c10d::ProcessGroup::BackendType::NCCL) {
nccl_groups.push_back(std::to_string(i));
}
}

Expand Down
22 changes: 18 additions & 4 deletions py/torch_tensorrt/dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,24 @@ def extract_var_range_info(symbolic_integer: torch.SymInt) -> Dict[str, Optional
or expr.xreplace(var_to_val_map)
)
assert var_range, var_val
min_val, max_val = (
int(var_range.lower),
int(var_range.upper) if var_range.upper != int_oo else None,
)

# ``var_to_range`` returns ``int_oo`` for unbounded; ``bound_sympy`` (used
# for composite exprs like ``s0+s1``) returns ``sympy.oo`` instead. They
# are distinct objects -- check both, else ``int(sympy.oo)`` raises.
def _bound_to_int_or_none(value: Any) -> Optional[int]:
if value is int_oo or value is -int_oo:
return None
if value == sympy.oo or value == -sympy.oo:
return None
try:
return int(value)
except (TypeError, OverflowError, AttributeError):
return None

min_val_opt = _bound_to_int_or_none(var_range.lower)
max_val = _bound_to_int_or_none(var_range.upper)
# Unbounded lower shouldn't happen for tensor dims; fall back to 1.
min_val = min_val_opt if min_val_opt is not None else 1

# Torchdynamo 0/1 specialization outlier
min_val = 1 if min_val == 2 else min_val
Expand Down
Loading