llmcompressor.pipelines.sequential.ast_helpers
Functions:
-
autowrap_forwards–Replace the
forwardmethod of the given modules with a recompiled version where
autowrap_forward
Replace the forward method of the given module with a recompiled version where
all untraceble code patterns are removed and replaced with torch.fx function
wrappers.
For a list of untraceable code patterns and their explainations, see https://github.com/vllm-project/llm-compressor/pull/1411
Parameters:
-
module(Module) –module whose forward method should be replaced
-
ignore(list[str]) –explicit list of function names to wrap
Source code in src/llmcompressor/pipelines/sequential/ast_helpers.py
autowrap_forwards
Replace the forward method of the given modules with a recompiled version where
all untraceble code patterns are removed and replaced with torch.fx function
wrappers
Parameters:
-
modules(list[Module]) –list of modules whose forward methods should be replaced
-
ignore(list[str]) –explicit list of function names to wrap
Source code in src/llmcompressor/pipelines/sequential/ast_helpers.py
get_unwrapped_forward
Get the original function which implements the forward method of a module,
stripping away any decorators which may have been applied to it.
inspect.unwrap only follows the __wrapped__ attribute, which is set by
decorators which use functools.wraps. Decorators which do not use
functools.wraps, such as transformers' force_accelerate_hooks (see
transformers/integrations/accelerate.py), leave no __wrapped__ attribute
behind, meaning that inspect.getsource returns the source of the wrapper,
which defines a function named wrapped rather than forward. In this case,
fall back to searching the wrapper's closure cells for the original function.
Note that the source of the original function includes its decorator lines, meaning that decorators are reapplied when the source is recompiled and their behavior is preserved (e.g. accelerate hook setup).
Parameters:
-
module(Module) –module whose forward function should be retrieved
Returns:
-
Callable–function which implements the module's forward method