aitune.torch.inspecting.module_inspector
aitune.torch.inspecting.module_inspector
Module for inspecting PyTorch models and tracking their execution.
This module is used to inspect PyTorch models and track their execution. It is used to find the modules that are executed and the modules that are not executed. It is also used to wrap the forward methods of the modules to track the execution time and input/output types.
In ModuleInspector, we use vars(obj) to get the members of an object.
Double references to the same module may cause issues. The inspector takes the first reference to the module that is inspected. So, even if the second reference is used for inference, the first will be returned for wrapping.
Object paths used in ModuleInfo are relative to the root module and are in all
dot notation, even for dictionaries and lists. (e.g., ‘.list.0.layers, '.dict.key.layers, .encoder.layers.0.self_attn.q_proj.weight).
Environment variables that could be used:
AITUNE_INSPECT_DEBUG: Whether to enable more verbose debug mode for inspecting. Adds visited nodes, and execution order. Default is False.
AITUNE_INSPECT_DEBUG_RAISE: Whether to raise an error when an error occurs during inspecting - ignored by default. Default is False.
Module Contents
Classes
Functions
Data
API
Context for inspecting modules.
Get the name.
Get the inspect context, with optional changes.
Get the ModuleInfo based on current context and provided object type.
Get the next inspect context - increment depth and add name to object path.
Class for inspecting PyTorch modules and tracking their execution.
Debug an error.
Debug inspecting functions.
Inspect the values of a dictionary.
Parameters:
The dictionary to inspect
The context of the inspection
Inspect the elements of a list.
Parameters:
The list to inspect
The context of the inspection
Inspect the members of an object.
Parameters:
The object to inspect
The members of the object to inspect
The context of the inspection
Start inspecting a module and its submodules.
Parameters:
The PyTorch module to inspect
The context of the inspection
Inspect an object and its members for PyTorch modules.
Parameters:
The object to inspect
The context of the inspection
Register a module and its submodules in the inspector.
Parameters:
The module to register
The parent module info if any
The context of the inspection
Check if a member should be skipped.
Wrap a method to add debug logging.
Wrap forward methods of a module and its submodules.
Parameters:
The module whose forward method to wrap
Get list of top-level executed modules or their first executed children.
Returns: list[ModuleInfo]
List of modules that were executed at the top level or their first executed children
Inspect an object and its members for PyTorch modules.
Parameters:
The object to inspect
Get the base class members of a PyTorch module.
Returns: list[str]
List of names
Reset the inspector state.