llmcompressor.pipelines.sequential.ast_utils.auto_wrapper
Classes:
-
AutoWrapper–Automatically wraps untracable code according to the following patterns:
AutoWrapper
Bases: NodeTransformer
Automatically wraps untracable code according to the following patterns:
The following patterns are automatically wrapped 1. If statements whose conditions cannot be statically evaluated 2. Ignored functions (_update_causal_mask) 3. Starred tuple unpacking 4. Starred argument unpacking
See also: https://github.com/vllm-project/llm-compressor/pull/1411
Methods:
-
auto_wrap–Modify ast by automatically wrapping any untraceable code segments. Segments to
-
visit_Call–Wrap any functions which use (4) variadic arguments or (2) match the ignore list
-
visit_Delete–Remove any deleted names from
self._local_names, -
visit_FunctionDef–Remove decorators which prevent forward function recompilation
-
visit_If–Attempt to statically evaluate the condition of the
ifstatement. If the -
visit_Name–Add any new names in
self._local_names, -
visit_Tuple–(3) Wrap any tuples which use starred unpacking
Source code in llmcompressor/pipelines/sequential/ast_utils/auto_wrapper.py
auto_wrap
Modify ast by automatically wrapping any untraceable code segments. Segments to wrap are determined through analysis of the code and basic pattern matching
Parameters:
-
(treeModule) –module containing a definition to an original forward function
Returns:
-
Module–module with added wrapper function definitions and function calls
Source code in llmcompressor/pipelines/sequential/ast_utils/auto_wrapper.py
visit_Call
Wrap any functions which use (4) variadic arguments or (2) match the ignore list
Source code in llmcompressor/pipelines/sequential/ast_utils/auto_wrapper.py
visit_Delete
Remove any deleted names from self._local_names, which are used to determine function wrapper arguments
Source code in llmcompressor/pipelines/sequential/ast_utils/auto_wrapper.py
visit_FunctionDef
Remove decorators which prevent forward function recompilation For example, add_start_docstrings_to_model_forward
Because _wrapper_fn_defs are appended after visit finishes, this function will not affect wrapper functions
Parameters:
-
(nodeFunctionDef) –function definition whose decorators will be stripped
Returns:
-
FunctionDef–function definition without decorators
Source code in llmcompressor/pipelines/sequential/ast_utils/auto_wrapper.py
visit_If
Attempt to statically evaluate the condition of the if statement. If the condition can not be statically evaluated (1), then attmept to wrap the if statement
Parameters:
-
(nodeIf) –ifstatement which may be wrapped
Returns:
-
If | Assign–if the
ifstatement cannot be statically evaluated, return theifstatement with the condition replaced byTrueorFalse. Otherwise, return a wrapper function call
Source code in llmcompressor/pipelines/sequential/ast_utils/auto_wrapper.py
visit_Name
Add any new names in self._local_names, which are used to determine function wrapper arguments
Source code in llmcompressor/pipelines/sequential/ast_utils/auto_wrapper.py
visit_Tuple
(3) Wrap any tuples which use starred unpacking