Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,8 +10,8 @@ import spaces
|
|
10 |
MODEL_NAME = "mistralai/Mistral-7B-v0.1"
|
11 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
12 |
|
13 |
-
torch_dtype = torch.float32
|
14 |
-
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch_dtype)
|
15 |
|
16 |
# === 2️⃣ LoRA AYARLARI ===
|
17 |
lora_config = LoraConfig(
|
@@ -21,22 +21,26 @@ lora_config = LoraConfig(
|
|
21 |
bias="none",
|
22 |
target_modules=["q_proj", "v_proj"],
|
23 |
)
|
24 |
-
model = get_peft_model(model, lora_config)
|
25 |
|
26 |
# === 3️⃣ VERİ SETİ ===
|
27 |
-
dataset = load_dataset("oscar", "unshuffled_deduplicated_tr", trust_remote_code=True)
|
28 |
-
subset = dataset["train"].shuffle(seed=42).select(range(10000))
|
29 |
-
|
30 |
@spaces.GPU
|
31 |
-
def
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
|
36 |
# === 4️⃣ EĞİTİM AYARLARI ===
|
37 |
batch_size = 1
|
38 |
num_epochs = 1
|
39 |
-
max_steps = (len(
|
40 |
|
41 |
training_args = TrainingArguments(
|
42 |
output_dir="./mistral_lora",
|
@@ -50,13 +54,14 @@ training_args = TrainingArguments(
|
|
50 |
logging_dir="./logs",
|
51 |
logging_steps=10,
|
52 |
optim="adamw_torch",
|
53 |
-
|
54 |
)
|
55 |
|
56 |
trainer = Trainer(
|
57 |
model=model,
|
58 |
args=training_args,
|
59 |
-
train_dataset=
|
|
|
60 |
)
|
61 |
|
62 |
@spaces.GPU
|
|
|
10 |
MODEL_NAME = "mistralai/Mistral-7B-v0.1"
|
11 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
12 |
|
13 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
14 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch_dtype, device_map="auto")
|
15 |
|
16 |
# === 2️⃣ LoRA AYARLARI ===
|
17 |
lora_config = LoraConfig(
|
|
|
21 |
bias="none",
|
22 |
target_modules=["q_proj", "v_proj"],
|
23 |
)
|
24 |
+
model = get_peft_model(model, lora_config).to("cuda" if torch.cuda.is_available() else "cpu")
|
25 |
|
26 |
# === 3️⃣ VERİ SETİ ===
|
|
|
|
|
|
|
27 |
@spaces.GPU
|
28 |
+
def load_and_prepare_dataset():
|
29 |
+
dataset = load_dataset("oscar", "unshuffled_deduplicated_tr", trust_remote_code=True)
|
30 |
+
subset = dataset["train"].shuffle(seed=42).select(range(10000))
|
31 |
+
|
32 |
+
def tokenize_function(examples):
|
33 |
+
return tokenizer(examples["text"], truncation=True, max_length=512)
|
34 |
+
|
35 |
+
tokenized_datasets = subset.map(tokenize_function, batched=True)
|
36 |
+
return tokenized_datasets.train_test_split(test_size=0.1, seed=42)
|
37 |
|
38 |
+
split_dataset = load_and_prepare_dataset()
|
39 |
|
40 |
# === 4️⃣ EĞİTİM AYARLARI ===
|
41 |
batch_size = 1
|
42 |
num_epochs = 1
|
43 |
+
max_steps = (len(split_dataset["train"]) // batch_size) * num_epochs
|
44 |
|
45 |
training_args = TrainingArguments(
|
46 |
output_dir="./mistral_lora",
|
|
|
54 |
logging_dir="./logs",
|
55 |
logging_steps=10,
|
56 |
optim="adamw_torch",
|
57 |
+
fp16=torch.cuda.is_available(),
|
58 |
)
|
59 |
|
60 |
trainer = Trainer(
|
61 |
model=model,
|
62 |
args=training_args,
|
63 |
+
train_dataset=split_dataset["train"],
|
64 |
+
eval_dataset=split_dataset["test"],
|
65 |
)
|
66 |
|
67 |
@spaces.GPU
|