torch.fx.experimental#
Created On: Feb 07, 2024 | Last Updated On: Nov 10, 2025
Warning
These APIs are experimental and subject to change without notice.
- class torch.fx.experimental.sym_node.DynamicInt(val)[source]#
User API for marking dynamic integers in torch.compile. Intended to be compatible with both compile and eager mode.
Example usage:
fn = torch.compile(f) x = DynamicInt(4) fn(x) # compiles x as a dynamic integer input; returns f(4)
torch.fx.experimental.sym_node#
torch.fx.experimental.symbolic_shapes#
ShapeEnv |
|
DimDynamic |
Controls how to perform symbol allocation for a dimension. |
StrictMinMaxConstraint |
For clients: the size at this dimension must be within 'vr' (which specifies a lower and upper bound, inclusive-inclusive) AND it must be non-negative and should not be 0 or 1 (but see NB below). |
RelaxedUnspecConstraint |
For clients: no explicit constraint; constraint is whatever is implicitly inferred by guards from tracing. |
EqualityConstraint |
Represent and decide various kinds of equality constraints between input sources. |
SymbolicContext |
Data structure specifying how we should create symbols in |
StatelessSymbolicContext |
Create symbols in |
StatefulSymbolicContext |
Create symbols in |
SubclassSymbolicContext |
The correct symbolic context for a given inner tensor of a traceable tensor subclass may differ from that of the outer symbolic context. |
DimConstraints |
Custom solver for a system of constraints on symbolic dimensions. |
ShapeEnvSettings |
Encapsulates all shape env settings that could potentially affect FakeTensor dispatch. |
ConvertIntKey |
|
CallMethodKey |
|
PropagateUnbackedSymInts |
|
DivideByKey |
|
InnerTensorKey |
|
Specialization |
This class is used in multi-graph compilation contexts where we generate multiple specialized graphs and dispatch to the appropriate one at runtime. |
hint_int |
Retrieve the hint for an int (based on the underlying real values as observed at runtime). |
is_concrete_int |
Utility to check if underlying object in SymInt is concrete value. |
is_concrete_bool |
Utility to check if underlying object in SymBool is concrete value. |
is_concrete_float |
Utility to check if underlying object in SymInt is concrete value. |
has_free_symbols |
Faster version of bool(free_symbols(val)) |
has_free_unbacked_symbols |
Faster version of bool(free_unbacked_symbols(val)) |
guard_or_true |
Try to guard a, if data dependent error encountered just return true. |
guard_or_false |
Try to guard a, if data dependent error encountered just return false. |
guard_size_oblivious |
Perform a guard on a symbolic boolean expression in a size oblivious way. |
sym_and |
and, but for symbolic expressions, without bool casting. |
sym_eq |
Like ==, but when run on list/tuple, it will recursively test equality and use sym_and to join the results together, without guarding. |
sym_or |
or, but for symbolic expressions, without bool casting. |
constrain_range |
Applies a constraint that the passed in SymInt must lie between min-max inclusive-inclusive, WITHOUT introducing a guard on the SymInt (meaning that it can be used on unbacked SymInts). |
constrain_unify |
Given two SymInts, constrain them so that they must be equal. |
canonicalize_bool_expr |
Canonicalize a boolean expression by transforming it into a lt / le inequality and moving all the non-constant terms to the rhs. |
statically_known_true |
Returns True if x can be simplified to a constant and is true. |
statically_known_false |
Returns True if x can be simplified to a constant and is False. |
has_static_value |
User-code friendly utility to check if a value is static or dynamic. |
lru_cache |
|
check_consistent |
Test that two "meta" values (typically either Tensor or SymInt) have the same values, e.g., after retracing. |
compute_unbacked_bindings |
After having run fake tensor propagation and producing example_value result, traverse example_value looking for freshly bound unbacked symbols and record their paths for later. |
rebind_unbacked |
Suppose we are retracing a pre-existing FX graph that previously had fake tensor propagation (and therefore unbacked SymInts). |
resolve_unbacked_bindings |
When we do fake tensor prop, we oftentimes will allocate new unbacked symints. |
is_accessor_node |
Helper function to determine if a node is trying to access a symbolic integer such as size, stride, offset or item. |
cast_symbool_to_symint_guardless |
Converts a SymBool or bool to a SymInt or int without introducing guards. |
create_contiguous |
|
error |
|
eval_guards |
|
eval_is_non_overlapping_and_dense |
|
find_symbol_binding_fx_nodes |
Find all nodes in an FX graph that bind sympy Symbols. |
free_symbols |
Recursively collect all free symbols from a value. |
free_unbacked_symbols |
Like free_symbols, but filtered to only report unbacked symbols |
fx_placeholder_targets |
|
fx_placeholder_vals |
|
guard_bool |
|
guard_float |
|
guard_int |
|
guard_scalar |
Guard a scalar value, which can be a symbolic or concrete boolean, integer, or float. |
has_hint |
|
has_symbolic_sizes_strides |
|
is_nested_int |
|
is_symbol_binding_fx_node |
Check if a given FX node is a symbol binding node. |
is_symbolic |
torch.fx.experimental.proxy_tensor#
make_fx |
Given a function f, return a new function which when executed with valid arguments to f, returns an FX GraphModule representing the set of operations that were executed during the course of execution. |
handle_sym_dispatch |
Call into the currently active proxy tracing mode to do a SymInt/SymFloat/SymBool dispatch trace on a function that operates on these arguments. |
get_proxy_mode |
Current the currently active proxy tracing mode, or None if we are not currently tracing. |
maybe_enable_thunkify |
Within this context manager, if you are doing make_fx tracing, we will thunkify all SymNode compute and avoid tracing it into the graph unless it is actually needed. |
maybe_disable_thunkify |
Within a context, disable thunkification. |
decompose |
|
disable_autocast_cache |
|
disable_proxy_modes_tracing |
|
extract_val |
|
fake_signature |
FX gets confused by varargs, de-confuse it |
fetch_object_proxy |
|
fetch_sym_proxy |
|
has_proxy_slot |
|
is_sym_node |
|
maybe_handle_decomp |
|
proxy_call |
|
set_meta |
|
set_original_aten_op |
|
set_proxy_slot |
|
snapshot_fake |
torch.fx.experimental.unification.unification_tools#
assoc |
Return a new dict with new key value pair |
assoc_in |
Return a new dict with new, potentially nested, key value pair |
dissoc |
Return a new dict with the given key(s) removed. |
first |
The first element in a sequence |
keyfilter |
Filter items in dictionary by key |
keymap |
Apply function to keys of dictionary |
merge |
Merge a collection of dictionaries |
merge_with |
Merge dictionaries and apply function to combined values |
update_in |
Update value in a (potentially) nested dictionary |
valfilter |
Filter items in dictionary by value |
valmap |
Apply function to values of dictionary |