aitune.torch.backend.torch_inductor_jit_backend
aitune.torch.backend.torch_inductor_jit_backend
Torch Inductor JIT backend.
Module Contents
Classes
Data
API
Bases: Backend
Backend that does torch compilation with Inductor.
Activates backend.
Builds the model with torch.compile.
Deactivates backend.
Deploys the backend.
Get the required casting dtype of the module by running a sample inference with and without autocast.
If the dtype of the output is different with and without autocast, return the dtype of the output without autocast. Otherwise, return None.
Parameters:
The module to get the dtype from.
List of sample inputs to run through the module.
Returns: torch.dtype | None
torch.dtype: The required casting dtype. Returns None if no casting is required.
Runs inference with the given arguments. Does not use autocast.
It can be replaced at runtime by _infer_with_autocast.
Parameters:
inference arguments
inference keyword arguments
Returns: Any
The result of the inference.
Runs inference with the given arguments.
Parameters:
inference arguments
inference keyword arguments
Returns: Any
The result of the inference.
Store the backend configuration to a file.
Returns the description of the backend.
Creates a backend from a state_dict.
Returns the key of the backend.
Returns the state_dict of the backend.
Bases: BackendConfig
Configuration for torch.compile with inductor backend.
Parameters:
If False (default), torch.compile attempts to discover compileable regions in the function it will tune. If True, then we require the entire function to be captured into a single graph. If this is not possible (that is, if there are graph breaks), then this will raise an error.
Use dynamic shape tracing. When this is True, we will up-front attempt to generate a kernel that is as dynamic as possible to avoid recompilations when sizes change. This may not always work as some operations/optimizations will force specialization; use TORCH_LOGS=dynamic to debug overspecialization. When this is False, we will NEVER generate dynamic kernels, we will always specialize. By default (None), we automatically detect if dynamism has occurred and compile a more dynamic kernel upon recompile.
Can be either “default”, “reduce-overhead”, “max-autotune” or “max-autotune-no-cudagraphs”.
-
“default” is the default mode, which is a good balance between performance and overhead
-
“reduce-overhead” is a mode that reduces the overhead of python with CUDA graphs, useful for small batches. Reduction of overhead can come at the cost of more memory usage, as we will cache the workspace memory required for the invocation so that we do not have to reallocate it on subsequent runs. Reduction of overhead is not guaranteed to work; today, we only reduce overhead for CUDA only graphs which do not mutate inputs. There are other circumstances where CUDA graphs are not applicable; use TORCH_LOG=perf_hints to debug.
-
“max-autotune” is a mode that leverages Triton or template based matrix multiplications on supported devices and Triton based convolutions on GPU. It enables CUDA graphs by default on GPU.
-
“max-autotune-no-cudagraphs” is a mode similar to “max-autotune” but without CUDA graphs
-
To see the exact configs that each mode sets you can call
torch._inductor.list_mode_options()
A dictionary of options to pass to the backend.
- To see the full list of configs that it supports by calling
torch._inductor.list_options()
If True, enable autocast.
The dtype to use for autocast.
inference is done with torch.no_grad() context. The torch.inference_mode() context must not be used
Post init.