kasim90 commited on
Commit
b94fa53
·
verified ·
1 Parent(s): 70f36d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -58
app.py CHANGED
@@ -16,66 +16,64 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
16
  zero = torch.Tensor([0]).cuda()
17
  print(zero.device) # <-- 'cpu' 🤔
18
 
19
- def greet(n):
20
- print(zero.device) # <-- 'cuda:0' 🤗
21
-
22
-
23
- print(zero.device) # <-- 'cuda:0' 🤗
24
-
25
-
26
-
27
- torch_dtype = torch.float32 # float32 seçtik çünkü CPU'da bf16 genelde yok
28
- model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch_dtype)
29
-
30
- # === 3️⃣ LoRA AYARLARI ===
31
- lora_config = LoraConfig(
32
- r=8,
33
- lora_alpha=32,
34
- lora_dropout=0.1,
35
- bias="none",
36
- target_modules=["q_proj", "v_proj"],
37
- )
38
- model = get_peft_model(model, lora_config)
39
 
40
- # === 4️⃣ VERİ SETİ ===
41
- dataset = load_dataset("oscar", "unshuffled_deduplicated_tr", trust_remote_code=True) # 🔥 ÇÖZÜM: trust_remote_code=True
42
- train_data = dataset["train"].shuffle(seed=42).select(range(10000)) # Küçük subset
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- # === 5️⃣ TOKENLEŞTİRME FONKSİYONU ===
45
- def tokenize_function(examples):
46
- return tokenizer(examples["text"], truncation=True, max_length=512)
47
 
48
- tokenized_datasets = train_data.map(tokenize_function, batched=True)
49
 
50
- # === 6️⃣ EĞİTİM AYARLARI ===
51
- training_args = TrainingArguments(
52
- output_dir="./mistral_lora_cpu",
53
- per_device_train_batch_size=1,
54
- gradient_accumulation_steps=16,
55
- learning_rate=5e-4,
56
- num_train_epochs=1,
57
- save_steps=500,
58
- save_total_limit=2,
59
- logging_dir="./logs",
60
- logging_steps=10,
61
- optim="adamw_torch", # 🔥 ÇÖZÜM: bitsandbytes yerine adamw_torch
62
  )
63
-
64
- # === 7️⃣ MODEL EĞİTİMİ ===
65
- @spaces.GPU
66
- def trainf():
67
-
68
- v= Trainer(
69
-
70
- model=model,
71
-
72
- args=training_args,
73
-
74
- train_dataset=tokenized_datasets,
75
-
76
- )
77
- return v
78
-
79
- trainf().train()
80
- demo = gr.Interface(fn=greet)
81
- demo.launch()
 
16
  zero = torch.Tensor([0]).cuda()
17
  print(zero.device) # <-- 'cpu' 🤔
18
 
19
+
20
+ print(zero.device) # <-- 'cuda:0' 🤗
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+
23
+ print(zero.device) # <-- 'cuda:0' 🤗
24
+
25
+
26
+
27
+ torch_dtype = torch.float32 # float32 seçtik çünkü CPU'da bf16 genelde yok
28
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch_dtype)
29
+
30
+ # === 3️⃣ LoRA AYARLARI ===
31
+ lora_config = LoraConfig(
32
+ r=8,
33
+ lora_alpha=32,
34
+ lora_dropout=0.1,
35
+ bias="none",
36
+ target_modules=["q_proj", "v_proj"],
37
+ )
38
+ model = get_peft_model(model, lora_config)
39
+
40
+ # === 4️⃣ VERİ SETİ ===
41
+ dataset = load_dataset("oscar", "unshuffled_deduplicated_tr", trust_remote_code=True) # 🔥 ÇÖZÜM: trust_remote_code=True
42
+ train_data = dataset["train"].shuffle(seed=42).select(range(10000)) # Küçük subset
43
+
44
+ # === 5️⃣ TOKENLEŞTİRME FONKSİYONU ===
45
+ def tokenize_function(examples):
46
+ return tokenizer(examples["text"], truncation=True, max_length=512)
47
+
48
+ tokenized_datasets = train_data.map(tokenize_function, batched=True)
49
+
50
+ # === 6️⃣ EĞİTİM AYARLARI ===
51
+ training_args = TrainingArguments(
52
+ output_dir="./mistral_lora_cpu",
53
+ per_device_train_batch_size=1,
54
+ gradient_accumulation_steps=16,
55
+ learning_rate=5e-4,
56
+ num_train_epochs=1,
57
+ save_steps=500,
58
+ save_total_limit=2,
59
+ logging_dir="./logs",
60
+ logging_steps=10,
61
+ optim="adamw_torch", # 🔥 ÇÖZÜM: bitsandbytes yerine adamw_torch
62
+ )
63
+
64
+ # === 7️⃣ MODEL EĞİTİMİ ===
65
+ @spaces.GPU
66
+ def trainf():
67
+
68
+ v= Trainer(
69
 
70
+ model=model,
 
 
71
 
72
+ args=training_args,
73
 
74
+ train_dataset=tokenized_datasets,
75
+
 
 
 
 
 
 
 
 
 
 
76
  )
77
+ return v
78
+
79
+ trainf().train()