Skip to content

Conversation

@vbaddi
Copy link
Contributor

@vbaddi vbaddi commented Feb 27, 2025

  • Refactor the finetune main api
  • Add support to override the PEFT config (yaml/json)
  • Add support to validate the correctness of PEFT Config
  • Some nit changes
r: 16
lora_alpha: 64
target_modules:
  - q_proj
  - v_proj
  - k_proj
bias: none
task_type: CAUSAL_LM
lora_dropout: 0.1

Command:

python -m QEfficient.cloud.finetune \
    --model_name "meta-llama/Llama-3.2-1B" \
    --lr 5e-4 \
    --peft_config_file "lora_config.yaml"

Using Default LoRA Config:

python -m QEfficient.cloud.finetune \
    --model_name "meta-llama/Llama-3.2-1B" \
    --lr 5e-4

@vbaddi vbaddi self-assigned this Feb 27, 2025
@vbaddi vbaddi force-pushed the add_peft_yaml_path branch from 2f19722 to 48061ee Compare February 27, 2025 13:57
@vbaddi vbaddi added the enhancement New feature or request label Mar 19, 2025
@quic-amitraj quic-amitraj marked this pull request as draft April 11, 2025 08:44
@ochougul ochougul closed this Apr 15, 2025
@quic-mamta quic-mamta reopened this Apr 16, 2025
finetune(**kwargs)
results = finetune(**kwargs)

assert np.allclose(results["avg_train_prep"], 1.002326, atol=1e-5), "Train perplexity is not matching."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avg_train_prep to be changed to avg_train_metric wrt changes in PR 292

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in latest.

gradient_accumulation_steps,
train_config: TRAIN_CONFIG,
train_config: TrainConfig,
device,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need of passing all three train_config.gradient_accumulation_steps, train_config and train_config.device, only train_config is enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in latest.

@quic-meetkuma quic-meetkuma force-pushed the add_peft_yaml_path branch 6 times, most recently from d0fff22 to e27deeb Compare April 21, 2025 11:28
- Ensures types match expected values (int, float, list, etc.).
"""
if config_type.lower() != "lora":
raise ValueError(f"Unsupported config_type: {config_type}. Only 'lora' is supported.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are not doing lora finetuning in case of BERT, it will raise error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is used only when peft_config_file is provided in main() function of finetune.py. Currently for BERT there wont be any peft_config_file. But if it is provided then PEFT training will happen for BERT.

Args:
config_data (Dict[str, Any]): The configuration dictionary loaded from YAML/JSON.
config_type (str): Type of config to validate ("lora" for LoraConfig, default: "lora").
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add field in config_type corresponding to BERT as we don't do lora fine tuning in it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lora can work with BERT but there is no point as BERT for sequence classification has random weights for classifier head.

# local_args = {k: v for k, v in locals().items() if v is not None and k != "peft_config_file" and k != "kwargs"}
update_config(train_config, **kwargs)

lora_config = LoraConfig()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is not required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in latest.

longest_seq_length, _ = get_longest_seq_length(train_dataloader.dataset)
lora_config = LoraConfig()

update_config(lora_config, **kwargs)
Copy link
Contributor

@quic-mamta quic-mamta Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do need to update lora_config here with kwargs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this code inside 'generate_peft_config' function. It was required so update the config params based on cli arguments.

@quic-meetkuma quic-meetkuma force-pushed the add_peft_yaml_path branch 2 times, most recently from 0bb2a51 to ada9de8 Compare April 28, 2025 09:54
def main(**kwargs):
"""
Helper function to finetune the model on QAic.
def setup_distributed_training(config: TrainConfig) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move these functions setup_distributed_training, setup_seeds, load_model_and_tokenizer, apply_peft and setup_dataloaders to other utils file and import in this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can take that in next PR. Keeping the refactored code in the same file for better comparison. Lot of refactoring is still required, we will do it in incremental fashion.

@quic-meetkuma quic-meetkuma force-pushed the add_peft_yaml_path branch 3 times, most recently from 1709b85 to 0aead82 Compare April 30, 2025 09:45
@quic-meetkuma quic-meetkuma force-pushed the add_peft_yaml_path branch 7 times, most recently from 8a5b6b6 to a4c8c50 Compare May 8, 2025 11:40
Signed-off-by: vbaddi <[email protected]>
Signed-off-by: Meet Patel <[email protected]>
Signed-off-by: Meet Patel <[email protected]>
… New PR will be raised to enable tests.

Signed-off-by: Meet Patel <[email protected]>
@quic-mamta quic-mamta merged commit 7d345dd into quic:main May 9, 2025
4 checks passed
mohiso22 pushed a commit to mohiso22/efficient_transformers that referenced this pull request May 14, 2025
- Refactor the finetune main api
- Add support to override the PEFT config (yaml/json)
- Add support to validate the correctness of PEFT Config
- Some nit changes

```yaml
r: 16
lora_alpha: 64
target_modules:
  - q_proj
  - v_proj
  - k_proj
bias: none
task_type: CAUSAL_LM
lora_dropout: 0.1
```
Command:
```bash
python -m QEfficient.cloud.finetune \
    --model_name "meta-llama/Llama-3.2-1B" \
    --lr 5e-4 \
    --peft_config_file "lora_config.yaml"
```

#### Using Default LoRA Config:
```bash
python -m QEfficient.cloud.finetune \
    --model_name "meta-llama/Llama-3.2-1B" \
    --lr 5e-4
```

---------

Signed-off-by: vbaddi <[email protected]>
Signed-off-by: Meet Patel <[email protected]>
Co-authored-by: Meet Patel <[email protected]>
Signed-off-by: Mohit Soni <[email protected]>
mohiso22 pushed a commit to mohiso22/efficient_transformers that referenced this pull request May 14, 2025
- Refactor the finetune main api
- Add support to override the PEFT config (yaml/json)
- Add support to validate the correctness of PEFT Config
- Some nit changes

```yaml
r: 16
lora_alpha: 64
target_modules:
  - q_proj
  - v_proj
  - k_proj
bias: none
task_type: CAUSAL_LM
lora_dropout: 0.1
```
Command:
```bash
python -m QEfficient.cloud.finetune \
    --model_name "meta-llama/Llama-3.2-1B" \
    --lr 5e-4 \
    --peft_config_file "lora_config.yaml"
```

#### Using Default LoRA Config:
```bash
python -m QEfficient.cloud.finetune \
    --model_name "meta-llama/Llama-3.2-1B" \
    --lr 5e-4
```

---------

Signed-off-by: vbaddi <[email protected]>
Signed-off-by: Meet Patel <[email protected]>
Co-authored-by: Meet Patel <[email protected]>
Signed-off-by: Mohit Soni <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fine-tuning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants