Converted QwQ notebooks to .py files
This commit is contained in:
@@ -6,7 +6,6 @@ Fine-tuning for QwQ model
|
||||
# Unsloth should be imported before transformers to ensure all optimizations are applied.
|
||||
from unsloth import FastLanguageModel, is_bfloat16_supported
|
||||
|
||||
from .dataset import Dataset
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from transformers import TrainingArguments
|
||||
@@ -15,6 +14,8 @@ from typing import Optional, List
|
||||
import argparse
|
||||
import os
|
||||
|
||||
from .dataset import Dataset
|
||||
|
||||
@dataclass
|
||||
class Args:
|
||||
def __init__(self, args: Optional[List[str]]):
|
||||
@@ -78,7 +79,7 @@ def main():
|
||||
load_in_4bit = True, # False for LoRA 16bit
|
||||
fast_inference = True, # Enable vLLM fast inference
|
||||
max_lora_rank = lora_rank,
|
||||
gpu_memory_utilization = 0.85, # Reduce if out of memory
|
||||
gpu_memory_utilization = 0.5, # Reduce if out of memory
|
||||
)
|
||||
|
||||
model = FastLanguageModel.get_peft_model(
|
||||
@@ -97,12 +98,6 @@ def main():
|
||||
loftq_config = None, # And LoftQ
|
||||
)
|
||||
|
||||
response_template = tokenizer.apply_chat_template(
|
||||
[{"role": "assistant", "content": ""}],
|
||||
tokenize=False,
|
||||
add_generation_prompt=True
|
||||
)
|
||||
|
||||
training_args = TrainingArguments(
|
||||
output_dir=str(args.output_dir),
|
||||
num_train_epochs=3,
|
||||
@@ -129,10 +124,6 @@ def main():
|
||||
train_dataset=dataset.to_transformers_dataset(tokenizer),
|
||||
dataset_text_field="messages",
|
||||
max_seq_length=max_seq_length,
|
||||
data_collator=DataCollatorForCompletionOnlyLM(
|
||||
response_template=response_template,
|
||||
tokenizer=tokenizer
|
||||
),
|
||||
)
|
||||
|
||||
trainer.train()
|
||||
@@ -140,7 +131,6 @@ def main():
|
||||
model.save_pretrained_merged(
|
||||
str(args.output_dir),
|
||||
tokenizer=tokenizer,
|
||||
save_method="merged_16bit"
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
||||
Reference in New Issue
Block a user