-
Notifications
You must be signed in to change notification settings - Fork 200
[Oneshot Refactor] dataclass Arguments #1103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
5cdae11
Dataclass Arg refactor -- recipe_args
horheynm a7cf946
refactor dataclass args
horheynm 6859adc
apply changes only for dataclass args - recipe, model, dataset, training
horheynm 7d19625
Merge branch 'main' into oneshot-refac-recipe_args
horheynm 6a1e4b0
fix tests
horheynm 44c67d7
Merge branch 'oneshot-refac-recipe_args' of github.com:vllm-project/l…
horheynm 7bb2e9a
pass cli tests
horheynm 0adb755
Merge branch 'main' into oneshot-refac-recipe_args
horheynm 12a2167
remove redundant code
horheynm cacfbed
Merge branch 'main' into oneshot-refac-recipe_args
horheynm 77205c0
comments
horheynm 377a10b
Merge branch 'oneshot-refac-recipe_args' of github.com:vllm-project/l…
horheynm 84ddf07
add type annotations to private func
horheynm 3770e6c
fix tests
horheynm 1f3110b
Merge branch 'main' into oneshot-refac-recipe_args
horheynm dbf7f8c
move to util
horheynm 656824e
fix tests
horheynm 48e382f
remove redudant code
horheynm be31960
examples TrainingArguments movement
horheynm 1253435
Merge branch 'main' into oneshot-refac-recipe_args
horheynm f4491be
revert to only refactor wrt to dataclass
horheynm 13ee157
remove unnec code
horheynm 48f531f
Merge branch 'main' into oneshot-refac-recipe_args
horheynm ce42137
Merge branch 'main' into oneshot-refac-recipe_args
horheynm 2fb8212
change optional to required in session_mixin
horheynm ef8fae0
Merge branch 'oneshot-refac-recipe_args' of github.com:vllm-project/l…
horheynm f0fc214
fix
horheynm 6e4c8cc
fix test
horheynm bcbfd35
comments
horheynm 049ddec
add
horheynm e671817
Merge branch 'main' into oneshot-refac-recipe_args
horheynm 68dd3b4
consistency
horheynm 63862c3
Update src/llmcompressor/arg_parser/README.md
horheynm afb8efa
comment
horheynm d50baba
comments
horheynm 9e26589
rename data_arguments to dataset_arguments
horheynm 7f49448
comments
horheynm a55a427
change directory name
horheynm 319d1bd
fix
horheynm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.