HeeBive commited on
Commit
6b00285
·
verified ·
1 Parent(s): 4538ef3

Upload train_gptoss_fixed.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_gptoss_fixed.sh +41 -0
train_gptoss_fixed.sh ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ pip install torch transformers peft trl datasets accelerate sentencepiece huggingface_hub -q 2>&1 | tail -1
4
+
5
+ python3 << 'PYEOF' > training.log 2>&1
6
+ import os, torch, shutil, json
7
+ os.environ["TORCH_COMPILE_DISABLE"] = "1"
8
+ TOKEN = "***"
9
+ REPO = "HeeBive/ZeroSec"
10
+
11
+ from huggingface_hub import hf_hub_download, HfApi
12
+ from datasets import Dataset
13
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
14
+ from peft import LoraConfig, get_peft_model
15
+ from trl import SFTTrainer
16
+
17
+ MODEL = "openai/gpt-oss-20b"
18
+ OUT = "./adapter"
19
+
20
+ print("DL data...")
21
+ p = hf_hub_download("HeeBive/ZeroSec-7B", "training_data.jsonl", repo_type="model", token=TOKEN)
22
+ raw = [json.loads(l) for l in open(p) if l.strip()]
23
+ print(f"{len(raw)} samples")
24
+ def f(e): return {"text": f"<|im_start|>user\n{e['instruction']}<|im_end|>\n<|im_start|>assistant\n{e['response']}<|im_end|>"}
25
+ ds = Dataset.from_list(raw).map(f)
26
+ tok = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
27
+ if tok.pad_token is None: tok.pad_token = tok.eos_token
28
+ ds = ds.map(lambda x: tok(x["text"], truncation=True, max_length=512), batched=True, remove_columns=ds.column_names)
29
+
30
+ print("Load model...")
31
+ m = AutoModelForCausalLM.from_pretrained(MODEL, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=True)
32
+ for p in m.parameters(): p.requires_grad = False
33
+ m.gradient_checkpointing_enable(gradient_checkpointing_kwargs={"use_reentrant": False})
34
+ m = get_peft_model(m, LoraConfig(r=16, lora_alpha=32, target_modules=["q_proj","k_proj","v_proj","o_proj"], task_type="CAUSAL_LM", bias="none"))
35
+ args = TrainingArguments(output_dir=OUT, per_device_train_batch_size=1, gradient_accumulation_steps=8, num_train_epochs=1, learning_rate=1e-4, bf16=True, logging_steps=5, optim="adamw_torch", report_to="none")
36
+ SFTTrainer(model=m, processing_class=tok, train_dataset=ds, args=args).train()
37
+ m.save_pretrained(OUT); tok.save_pretrained(OUT)
38
+ print("Uploading...")
39
+ HfApi(token=TOKEN).upload_folder(folder_path=OUT, repo_id=REPO, repo_type="model", token=TOKEN)
40
+ print(f"✅ {REPO}")
41
+ PYEOF