Spaces:
Sleeping
Sleeping
Upload run_cloud_training.py with huggingface_hub
Browse files- run_cloud_training.py +20 -9
run_cloud_training.py
CHANGED
|
@@ -259,8 +259,9 @@ def train(config_path, dataset_name, output_dir):
|
|
| 259 |
logger.info("Initializing model with unsloth (preserving 4-bit quantization)")
|
| 260 |
max_seq_length = training_config.get("max_seq_length", 2048)
|
| 261 |
|
| 262 |
-
# Create LoRA config
|
| 263 |
-
|
|
|
|
| 264 |
r=lora_config.get("r", 16),
|
| 265 |
lora_alpha=lora_config.get("lora_alpha", 32),
|
| 266 |
lora_dropout=lora_config.get("lora_dropout", 0.05),
|
|
@@ -273,14 +274,24 @@ def train(config_path, dataset_name, output_dir):
|
|
| 273 |
dtype = torch.float16 if hardware_config.get("fp16", True) else None
|
| 274 |
model, tokenizer = load_model_safely(model_name, max_seq_length, dtype)
|
| 275 |
|
| 276 |
-
# Apply LoRA
|
| 277 |
logger.info("Applying LoRA to model")
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
# No need to format the dataset - it's already pre-tokenized
|
| 286 |
logger.info("Using pre-tokenized dataset - skipping tokenization step")
|
|
|
|
| 259 |
logger.info("Initializing model with unsloth (preserving 4-bit quantization)")
|
| 260 |
max_seq_length = training_config.get("max_seq_length", 2048)
|
| 261 |
|
| 262 |
+
# Create LoRA config directly
|
| 263 |
+
logger.info("Creating LoRA configuration")
|
| 264 |
+
lora_config_obj = LoraConfig(
|
| 265 |
r=lora_config.get("r", 16),
|
| 266 |
lora_alpha=lora_config.get("lora_alpha", 32),
|
| 267 |
lora_dropout=lora_config.get("lora_dropout", 0.05),
|
|
|
|
| 274 |
dtype = torch.float16 if hardware_config.get("fp16", True) else None
|
| 275 |
model, tokenizer = load_model_safely(model_name, max_seq_length, dtype)
|
| 276 |
|
| 277 |
+
# Apply LoRA - correctly passing lora_config_obj directly
|
| 278 |
logger.info("Applying LoRA to model")
|
| 279 |
+
try:
|
| 280 |
+
logger.info("Attempting to apply LoRA with unsloth API")
|
| 281 |
+
model = FastLanguageModel.get_peft_model(
|
| 282 |
+
model,
|
| 283 |
+
lora_config=lora_config_obj, # Pass lora_config directly instead of peft_config
|
| 284 |
+
tokenizer=tokenizer,
|
| 285 |
+
use_gradient_checkpointing=hardware_config.get("gradient_checkpointing", True)
|
| 286 |
+
)
|
| 287 |
+
except Exception as e:
|
| 288 |
+
logger.warning(f"Error applying LoRA with unsloth: {e}")
|
| 289 |
+
logger.info("Falling back to standard PEFT method")
|
| 290 |
+
|
| 291 |
+
# Try with standard PEFT approach if unsloth fails
|
| 292 |
+
from peft import get_peft_model
|
| 293 |
+
model = get_peft_model(model, lora_config_obj)
|
| 294 |
+
logger.info("Successfully applied LoRA with standard PEFT")
|
| 295 |
|
| 296 |
# No need to format the dataset - it's already pre-tokenized
|
| 297 |
logger.info("Using pre-tokenized dataset - skipping tokenization step")
|