Text Generation
PEFT
English
cybersecurity
penetration-testing
exploit-development
offensive-security
lora
qwen
code
Instructions to use HeeBive/ZeroSec-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use HeeBive/ZeroSec-7B with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Upload train_gptoss.sh with huggingface_hub
Browse files- train_gptoss.sh +43 -0
train_gptoss.sh
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
TOKEN="${HF_TOKEN:?Set HF_TOKEN first}"
|
| 6 |
+
REPO="${HF_REPO_ID:-HeeBive/ZeroSec}"
|
| 7 |
+
|
| 8 |
+
python3 << 'PYEOF' > training.log 2>&1
|
| 9 |
+
import os, torch, shutil, json
|
| 10 |
+
os.environ["TORCH_COMPILE_DISABLE"] = "1"
|
| 11 |
+
TOKEN = os.environ.get("HF_TOKEN")
|
| 12 |
+
REPO = os.environ.get("HF_REPO_ID", "HeeBive/ZeroSec")
|
| 13 |
+
from huggingface_hub import hf_hub_download, HfApi
|
| 14 |
+
from datasets import Dataset
|
| 15 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
|
| 16 |
+
from peft import LoraConfig, get_peft_model
|
| 17 |
+
from trl import SFTTrainer
|
| 18 |
+
|
| 19 |
+
MODEL = "openai/gpt-oss-20b"
|
| 20 |
+
OUT = "./adapter"
|
| 21 |
+
|
| 22 |
+
print("DL data...")
|
| 23 |
+
p = hf_hub_download("HeeBive/ZeroSec-7B", "training_data.jsonl", repo_type="model", token=TOKEN)
|
| 24 |
+
raw = [json.loads(l) for l in open(p) if l.strip()]
|
| 25 |
+
print(f"{len(raw)} samples")
|
| 26 |
+
def f(e): return {"text": f"<|im_start|>user\n{e['instruction']}<|im_end|>\n<|im_start|>assistant\n{e['response']}<|im_end|>"}
|
| 27 |
+
ds = Dataset.from_list(raw).map(f)
|
| 28 |
+
tok = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
|
| 29 |
+
if tok.pad_token is None: tok.pad_token = tok.eos_token
|
| 30 |
+
ds = ds.map(lambda x: tok(x["text"], truncation=True, max_length=512), batched=True, remove_columns=ds.column_names)
|
| 31 |
+
|
| 32 |
+
print("Load model...")
|
| 33 |
+
m = AutoModelForCausalLM.from_pretrained(MODEL, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=True)
|
| 34 |
+
for p in m.parameters(): p.requires_grad = False
|
| 35 |
+
m.gradient_checkpointing_enable()
|
| 36 |
+
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"))
|
| 37 |
+
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")
|
| 38 |
+
SFTTrainer(model=m, processing_class=tok, train_dataset=ds, args=args).train()
|
| 39 |
+
m.save_pretrained(OUT); tok.save_pretrained(OUT)
|
| 40 |
+
print("Uploading...")
|
| 41 |
+
HfApi(token=TOKEN).upload_folder(folder_path=OUT, repo_id=REPO, repo_type="model", token=TOKEN)
|
| 42 |
+
print(f"✅ {REPO}")
|
| 43 |
+
PYEOF
|