-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into oneshot-refac-initialize_model_from_path
- Loading branch information
Showing
38 changed files
with
283 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Input arguments for `oneshot`, `train`, `eval` entrypoints | ||
|
||
Parsers in `llm-compressor` define the input arguments required for various entry points, including `oneshot`, `train`, and `eval`. | ||
|
||
Each entry point (e.g., oneshot) carries out its logic based on the provided input arguments, `model`, `recipe`, and `dataset`. | ||
|
||
```python | ||
from llmcompressor.transformers import oneshot | ||
|
||
model = ... | ||
recipe = ... | ||
dataset = ... | ||
oneshot(model=model, recipe=recipe, dataset=dataset) | ||
``` | ||
|
||
In addition, users can futher control execution by providing additional arguments. For example, to save the optimized model after completion, the `output_dir` parameter can be specified: | ||
|
||
```python | ||
oneshot( | ||
..., | ||
output_dir=..., | ||
) | ||
``` | ||
|
||
These input arguments can be overloaded into the function signature and will be parsed using Hugging Face's [argument parser](https://github.com/huggingface/transformers/blob/main/src/transformers/hf_argparser.py). The parsers define the acceptable inputs; therefore any arguments to be passed in must be defined. | ||
|
||
`llm-compressor` uses four parsers, located in `llm_compressor/arg_parser`: | ||
* ModelArguments | ||
* DatasetArguments | ||
* RecipeArguments | ||
* TrainingArguments | ||
|
||
|
||
## ModelArguments | ||
Handles model loading and saving. For example, `ModelArguments.model` can be a Hugging Face model identifier or an instance of `AutoModelForCausalLM`. The `save_compressed` flag is a boolean that determines whether the model is saved in compressed safetensors format to minimize disk usage. | ||
|
||
## DataArguments | ||
Manages data loading and preprocessing. The dataset argument can specify a Hugging Face dataset stub or a local dataset compatible with [`load_dataset`](https://github.com/huggingface/datasets/blob/3a4e74a9ace62ecd5c9cde7dcb6bcabd65cc7857/src/datasets/load.py#L1905). The preprocessing_func is a callable function that applies custom logic, such as formatting the data using a chat template. | ||
|
||
## RecipeArguments | ||
Defines the model recipe. A `recipe` consists of user-defined instructions for optimizing the model. Examples of recipes can be found in the `/examples` directory. | ||
|
||
## TrainingArguments | ||
Specifies training parameters based on Hugging Face's [TrainingArguments class](https://github.com/huggingface/transformers/blob/main/src/transformers/training_args.py). These parameters include settings like learning rate (`learning_rate`), and the optimizer to use (`optim`). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# flake8: noqa | ||
|
||
from .dataset_arguments import DatasetArguments | ||
from .model_arguments import ModelArguments | ||
from .recipe_arguments import RecipeArguments | ||
from .training_arguments import TrainingArguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from dataclasses import dataclass, field | ||
from typing import List, Optional | ||
|
||
|
||
@dataclass | ||
class RecipeArguments: | ||
"""Recipe and session variables""" | ||
|
||
recipe: Optional[str] = field( | ||
default=None, | ||
metadata={ | ||
"help": "Path to a LLM Compressor sparsification recipe", | ||
}, | ||
) | ||
recipe_args: Optional[List[str]] = field( | ||
default=None, | ||
metadata={ | ||
"help": ( | ||
"List of recipe arguments to evaluate, of the format key1=value1 " | ||
"key2=value2" | ||
) | ||
}, | ||
) | ||
clear_sparse_session: Optional[bool] = field( | ||
default=False, | ||
metadata={ | ||
"help": ( | ||
"Whether to clear CompressionSession/CompressionLifecycle ", | ||
"data between runs.", | ||
) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Optional | ||
|
||
from transformers import TrainingArguments as HFTrainingArgs | ||
|
||
__all__ = [ | ||
"TrainingArguments", | ||
] | ||
|
||
|
||
@dataclass | ||
class TrainingArguments(HFTrainingArgs): | ||
""" | ||
Training arguments specific to LLM Compressor Transformers workflow using | ||
HFTrainingArgs as base class | ||
""" | ||
|
||
do_oneshot: Optional[bool] = field( | ||
default=False, | ||
metadata={"help": "Whether to run one-shot calibration in stages"}, | ||
) | ||
run_stages: Optional[bool] = field( | ||
default=False, metadata={"help": "Whether to trigger recipe stage by stage"} | ||
) | ||
output_dir: str = field( | ||
default="./output", | ||
metadata={ | ||
"help": "The output directory where the model predictions and " | ||
"checkpoints will be written." | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# flake8: noqa | ||
|
||
from .data import DataTrainingArguments, TextGenerationDataset | ||
from .model_args import ModelArguments | ||
from .data import TextGenerationDataset | ||
from .session_mixin import SessionManagerMixIn | ||
from .text_generation import apply, compress, eval, oneshot, train | ||
from .training_args import TrainingArguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.