Text Generation
Transformers
English
qwen2
code-generation
python
fine-tuning
Qwen
tools
agent-framework
multi-agent
conversational
Eval Results (legacy)
Instructions to use my-ai-stack/Stack-2-9-finetuned with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use my-ai-stack/Stack-2-9-finetuned with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="my-ai-stack/Stack-2-9-finetuned") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("my-ai-stack/Stack-2-9-finetuned") model = AutoModelForCausalLM.from_pretrained("my-ai-stack/Stack-2-9-finetuned", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use my-ai-stack/Stack-2-9-finetuned with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "my-ai-stack/Stack-2-9-finetuned" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/my-ai-stack/Stack-2-9-finetuned
- SGLang
How to use my-ai-stack/Stack-2-9-finetuned with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "my-ai-stack/Stack-2-9-finetuned" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "my-ai-stack/Stack-2-9-finetuned" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "my-ai-stack/Stack-2-9-finetuned", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use my-ai-stack/Stack-2-9-finetuned with Docker Model Runner:
docker model run hf.co/my-ai-stack/Stack-2-9-finetuned
walidsobhie-code commited on
Commit ·
732bef9
1
Parent(s): 4ce3e59
revert bitsandbytes: CUDA 13 runtime missing on Kaggle
Browse filesbitsandbytes 4-bit quantization requires libnvJitLink.so.13 which
is not available in the Kaggle CUDA 11.8 environment.
Switching back to bfloat16-only training (no quantization):
- train_simple_nobnb.py: bfloat16 by default, 4-bit as opt-in flag
- notebook: use_4bit=False, no bitsandbytes pip install
- merge_simple.py: also uses bfloat16 for consistency
VRAM usage with bf16 LoRA on T4 should still be manageable with
batch_size=1 + gradient_accumulation=8
- kaggle_train_stack29_v5.ipynb +9 -15
- train_simple_nobnb.py +9 -13
kaggle_train_stack29_v5.ipynb
CHANGED
|
@@ -8,17 +8,12 @@
|
|
| 8 |
"\n",
|
| 9 |
"Free GPU training on Kaggle using Qwen2.5-Coder-7B.\n",
|
| 10 |
"\n",
|
| 11 |
-
"⏱️ **Runtime:** 2-4 hours | 💾 **VRAM:** ~
|
| 12 |
"\n",
|
| 13 |
"**Setup:**\n",
|
| 14 |
"1. Settings → Accelerator → GPU **T4**\n",
|
| 15 |
"2. Run all cells in order\n",
|
| 16 |
-
"3. Download merged model from Output tab when done
|
| 17 |
-
"\n",
|
| 18 |
-
"**Key fixes in v5:**\n",
|
| 19 |
-
"- ✅ 4-bit NF4 quantization (saves ~10GB VRAM)\n",
|
| 20 |
-
"- ✅ bfloat16 training (instead of float16)\n",
|
| 21 |
-
"- ✅ bitsandbytes installed automatically"
|
| 22 |
]
|
| 23 |
},
|
| 24 |
{
|
|
@@ -70,8 +65,8 @@
|
|
| 70 |
"metadata": {},
|
| 71 |
"outputs": [],
|
| 72 |
"source": [
|
| 73 |
-
"# Install dependencies (
|
| 74 |
-
"!pip install -q transformers==4.40.0 peft==0.10.0 accelerate==0.34.0 datasets==3.0.0 pyyaml tqdm scipy
|
| 75 |
"print('✅ Dependencies ready')"
|
| 76 |
]
|
| 77 |
},
|
|
@@ -127,7 +122,7 @@
|
|
| 127 |
"outputs": [],
|
| 128 |
"source": [
|
| 129 |
"# Generate training configuration\n",
|
| 130 |
-
"#
|
| 131 |
"import yaml\n",
|
| 132 |
"\n",
|
| 133 |
"os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
|
|
@@ -138,8 +133,8 @@
|
|
| 138 |
" 'lora': {'r': 16, 'alpha': 32, 'dropout': 0.05, 'target_modules': ['q_proj', 'k_proj', 'v_proj', 'o_proj', 'gate_proj', 'up_proj', 'down_proj'], 'bias': 'none', 'task_type': 'CAUSAL_LM'},\n",
|
| 139 |
" 'training': {'num_epochs': 1, 'batch_size': 1, 'gradient_accumulation': 8, 'learning_rate': 2e-4, 'warmup_steps': 50, 'weight_decay': 0.01, 'max_grad_norm': 1.0, 'logging_steps': 10, 'save_steps': 100, 'save_total_limit': 2, 'fp16': False, 'bf16': True, 'gradient_checkpointing': True},\n",
|
| 140 |
" 'output': {'lora_dir': os.path.join(OUTPUT_DIR, 'lora'), 'logging_dir': os.path.join(OUTPUT_DIR, 'logs')},\n",
|
| 141 |
-
" 'quantization': {'enabled':
|
| 142 |
-
" 'hardware': {'device': 'cuda', 'num_gpus': 1, 'use_4bit':
|
| 143 |
"}\n",
|
| 144 |
"\n",
|
| 145 |
"config_path = os.path.join(OUTPUT_DIR, 'train_config.yaml')\n",
|
|
@@ -149,7 +144,6 @@
|
|
| 149 |
"print(f'✅ Config: {config_path}')\n",
|
| 150 |
"print(f\" Model: {config['model']['name']}\")\n",
|
| 151 |
"print(f\" Data: {config['data']['input_path']}\")\n",
|
| 152 |
-
"print(f\" Quantization: 4-bit={config['hardware']['use_4bit']}\")\n",
|
| 153 |
"print(f\" bf16={config['training']['bf16']}, fp16={config['training']['fp16']}\")"
|
| 154 |
]
|
| 155 |
},
|
|
@@ -159,9 +153,9 @@
|
|
| 159 |
"metadata": {},
|
| 160 |
"outputs": [],
|
| 161 |
"source": [
|
| 162 |
-
"# Train (using standalone train_simple_nobnb.py -
|
| 163 |
"print('='*60)\n",
|
| 164 |
-
"print('STARTING TRAINING (
|
| 165 |
"print('='*60)\n",
|
| 166 |
"\n",
|
| 167 |
"!cd {REPO_DIR} && python train_simple_nobnb.py --config {config_path}\n",
|
|
|
|
| 8 |
"\n",
|
| 9 |
"Free GPU training on Kaggle using Qwen2.5-Coder-7B.\n",
|
| 10 |
"\n",
|
| 11 |
+
"⏱️ **Runtime:** 2-4 hours | 💾 **VRAM:** ~14GB (bfloat16, no bitsandbytes)\n",
|
| 12 |
"\n",
|
| 13 |
"**Setup:**\n",
|
| 14 |
"1. Settings → Accelerator → GPU **T4**\n",
|
| 15 |
"2. Run all cells in order\n",
|
| 16 |
+
"3. Download merged model from Output tab when done"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
]
|
| 18 |
},
|
| 19 |
{
|
|
|
|
| 65 |
"metadata": {},
|
| 66 |
"outputs": [],
|
| 67 |
"source": [
|
| 68 |
+
"# Install other dependencies (NO bitsandbytes — bfloat16 only)\n",
|
| 69 |
+
"!pip install -q transformers==4.40.0 peft==0.10.0 accelerate==0.34.0 datasets==3.0.0 pyyaml tqdm scipy\n",
|
| 70 |
"print('✅ Dependencies ready')"
|
| 71 |
]
|
| 72 |
},
|
|
|
|
| 122 |
"outputs": [],
|
| 123 |
"source": [
|
| 124 |
"# Generate training configuration\n",
|
| 125 |
+
"# Uses bfloat16 only (NO bitsandbytes — avoids CUDA 13 dependency issues)\n",
|
| 126 |
"import yaml\n",
|
| 127 |
"\n",
|
| 128 |
"os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
|
|
|
|
| 133 |
" 'lora': {'r': 16, 'alpha': 32, 'dropout': 0.05, 'target_modules': ['q_proj', 'k_proj', 'v_proj', 'o_proj', 'gate_proj', 'up_proj', 'down_proj'], 'bias': 'none', 'task_type': 'CAUSAL_LM'},\n",
|
| 134 |
" 'training': {'num_epochs': 1, 'batch_size': 1, 'gradient_accumulation': 8, 'learning_rate': 2e-4, 'warmup_steps': 50, 'weight_decay': 0.01, 'max_grad_norm': 1.0, 'logging_steps': 10, 'save_steps': 100, 'save_total_limit': 2, 'fp16': False, 'bf16': True, 'gradient_checkpointing': True},\n",
|
| 135 |
" 'output': {'lora_dir': os.path.join(OUTPUT_DIR, 'lora'), 'logging_dir': os.path.join(OUTPUT_DIR, 'logs')},\n",
|
| 136 |
+
" 'quantization': {'enabled': False},\n",
|
| 137 |
+
" 'hardware': {'device': 'cuda', 'num_gpus': 1, 'use_4bit': False, 'use_8bit': False}\n",
|
| 138 |
"}\n",
|
| 139 |
"\n",
|
| 140 |
"config_path = os.path.join(OUTPUT_DIR, 'train_config.yaml')\n",
|
|
|
|
| 144 |
"print(f'✅ Config: {config_path}')\n",
|
| 145 |
"print(f\" Model: {config['model']['name']}\")\n",
|
| 146 |
"print(f\" Data: {config['data']['input_path']}\")\n",
|
|
|
|
| 147 |
"print(f\" bf16={config['training']['bf16']}, fp16={config['training']['fp16']}\")"
|
| 148 |
]
|
| 149 |
},
|
|
|
|
| 153 |
"metadata": {},
|
| 154 |
"outputs": [],
|
| 155 |
"source": [
|
| 156 |
+
"# Train (using standalone train_simple_nobnb.py - bfloat16, no quantization)\n",
|
| 157 |
"print('='*60)\n",
|
| 158 |
+
"print('STARTING TRAINING (bfloat16, no quantization)')\n",
|
| 159 |
"print('='*60)\n",
|
| 160 |
"\n",
|
| 161 |
"!cd {REPO_DIR} && python train_simple_nobnb.py --config {config_path}\n",
|
train_simple_nobnb.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
Simple standalone training script for Stack 2.9.
|
| 4 |
-
Uses 4-bit quantization
|
| 5 |
"""
|
| 6 |
|
| 7 |
import argparse
|
|
@@ -16,7 +16,6 @@ from transformers import (
|
|
| 16 |
TrainingArguments,
|
| 17 |
Trainer,
|
| 18 |
DataCollatorForLanguageModeling,
|
| 19 |
-
BitsAndBytesConfig,
|
| 20 |
)
|
| 21 |
from peft import LoraConfig, get_peft_model, TaskType
|
| 22 |
import torch
|
|
@@ -32,11 +31,13 @@ def load_model_and_tokenizer(
|
|
| 32 |
trust_remote_code: bool = True,
|
| 33 |
use_4bit: bool = False,
|
| 34 |
):
|
| 35 |
-
"""Load base model with optional 4-bit quantization."""
|
| 36 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 37 |
model_name, trust_remote_code=trust_remote_code
|
| 38 |
)
|
|
|
|
| 39 |
if use_4bit:
|
|
|
|
| 40 |
bnb_config = BitsAndBytesConfig(
|
| 41 |
load_in_4bit=True,
|
| 42 |
bnb_4bit_quant_type="nf4",
|
|
@@ -56,6 +57,7 @@ def load_model_and_tokenizer(
|
|
| 56 |
trust_remote_code=trust_remote_code,
|
| 57 |
device_map={"": torch.device("cuda")},
|
| 58 |
)
|
|
|
|
| 59 |
return model, tokenizer
|
| 60 |
|
| 61 |
|
|
@@ -103,17 +105,13 @@ def load_data(
|
|
| 103 |
# Handle train_split logic
|
| 104 |
total_samples = len(tokenized_dataset)
|
| 105 |
if train_split >= 1.0:
|
| 106 |
-
# Absolute number of training samples
|
| 107 |
n_train = int(train_split)
|
| 108 |
if n_train >= total_samples:
|
| 109 |
-
# Use all data for training, no eval set
|
| 110 |
return tokenized_dataset, None
|
| 111 |
else:
|
| 112 |
-
# Split with exact number
|
| 113 |
split = tokenized_dataset.train_test_split(train_size=n_train)
|
| 114 |
return split["train"], split["test"]
|
| 115 |
else:
|
| 116 |
-
# Fractional split
|
| 117 |
split = tokenized_dataset.train_test_split(train_size=train_split)
|
| 118 |
return split["train"], split["test"]
|
| 119 |
|
|
@@ -126,9 +124,8 @@ def train(config: dict):
|
|
| 126 |
training_config = config["training"]
|
| 127 |
output_config = config["output"]
|
| 128 |
hardware_config = config.get("hardware", {})
|
| 129 |
-
quantization_config = config.get("quantization", {})
|
| 130 |
|
| 131 |
-
use_4bit = hardware_config.get("use_4bit", False)
|
| 132 |
|
| 133 |
# Load model and tokenizer
|
| 134 |
print(f"Loading model: {model_config['name']} (4bit={use_4bit})")
|
|
@@ -164,8 +161,7 @@ def train(config: dict):
|
|
| 164 |
model = get_peft_model(model, peft_config)
|
| 165 |
model.print_trainable_parameters()
|
| 166 |
|
| 167 |
-
# Enable gradient checkpointing with
|
| 168 |
-
# (required for PyTorch 2.9+ compatibility)
|
| 169 |
if training_config.get("gradient_checkpointing", True):
|
| 170 |
model.gradient_checkpointing_enable(
|
| 171 |
gradient_checkpointing_kwargs={"use_reentrant": False}
|
|
@@ -177,7 +173,7 @@ def train(config: dict):
|
|
| 177 |
gradient_checkpointing_kwargs={"use_reentrant": False}
|
| 178 |
)
|
| 179 |
|
| 180 |
-
# Training arguments
|
| 181 |
output_dir = output_config["lora_dir"]
|
| 182 |
os.makedirs(output_dir, exist_ok=True)
|
| 183 |
|
|
@@ -193,7 +189,7 @@ def train(config: dict):
|
|
| 193 |
logging_steps=training_config.get("logging_steps", 10),
|
| 194 |
save_steps=training_config.get("save_steps", 100),
|
| 195 |
save_total_limit=training_config.get("save_total_limit", 2),
|
| 196 |
-
bf16=True,
|
| 197 |
fp16=False,
|
| 198 |
gradient_checkpointing=training_config.get("gradient_checkpointing", True),
|
| 199 |
evaluation_strategy="steps" if eval_dataset else "no",
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
Simple standalone training script for Stack 2.9.
|
| 4 |
+
Uses bfloat16 with optional 4-bit quantization via bitsandbytes.
|
| 5 |
"""
|
| 6 |
|
| 7 |
import argparse
|
|
|
|
| 16 |
TrainingArguments,
|
| 17 |
Trainer,
|
| 18 |
DataCollatorForLanguageModeling,
|
|
|
|
| 19 |
)
|
| 20 |
from peft import LoraConfig, get_peft_model, TaskType
|
| 21 |
import torch
|
|
|
|
| 31 |
trust_remote_code: bool = True,
|
| 32 |
use_4bit: bool = False,
|
| 33 |
):
|
| 34 |
+
"""Load base model in bfloat16, with optional 4-bit quantization."""
|
| 35 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 36 |
model_name, trust_remote_code=trust_remote_code
|
| 37 |
)
|
| 38 |
+
|
| 39 |
if use_4bit:
|
| 40 |
+
from transformers import BitsAndBytesConfig
|
| 41 |
bnb_config = BitsAndBytesConfig(
|
| 42 |
load_in_4bit=True,
|
| 43 |
bnb_4bit_quant_type="nf4",
|
|
|
|
| 57 |
trust_remote_code=trust_remote_code,
|
| 58 |
device_map={"": torch.device("cuda")},
|
| 59 |
)
|
| 60 |
+
|
| 61 |
return model, tokenizer
|
| 62 |
|
| 63 |
|
|
|
|
| 105 |
# Handle train_split logic
|
| 106 |
total_samples = len(tokenized_dataset)
|
| 107 |
if train_split >= 1.0:
|
|
|
|
| 108 |
n_train = int(train_split)
|
| 109 |
if n_train >= total_samples:
|
|
|
|
| 110 |
return tokenized_dataset, None
|
| 111 |
else:
|
|
|
|
| 112 |
split = tokenized_dataset.train_test_split(train_size=n_train)
|
| 113 |
return split["train"], split["test"]
|
| 114 |
else:
|
|
|
|
| 115 |
split = tokenized_dataset.train_test_split(train_size=train_split)
|
| 116 |
return split["train"], split["test"]
|
| 117 |
|
|
|
|
| 124 |
training_config = config["training"]
|
| 125 |
output_config = config["output"]
|
| 126 |
hardware_config = config.get("hardware", {})
|
|
|
|
| 127 |
|
| 128 |
+
use_4bit = hardware_config.get("use_4bit", False)
|
| 129 |
|
| 130 |
# Load model and tokenizer
|
| 131 |
print(f"Loading model: {model_config['name']} (4bit={use_4bit})")
|
|
|
|
| 161 |
model = get_peft_model(model, peft_config)
|
| 162 |
model.print_trainable_parameters()
|
| 163 |
|
| 164 |
+
# Enable gradient checkpointing with use_reentrant=False (required for PyTorch 2.9+)
|
|
|
|
| 165 |
if training_config.get("gradient_checkpointing", True):
|
| 166 |
model.gradient_checkpointing_enable(
|
| 167 |
gradient_checkpointing_kwargs={"use_reentrant": False}
|
|
|
|
| 173 |
gradient_checkpointing_kwargs={"use_reentrant": False}
|
| 174 |
)
|
| 175 |
|
| 176 |
+
# Training arguments — bf16 is safe for both full and quantized models
|
| 177 |
output_dir = output_config["lora_dir"]
|
| 178 |
os.makedirs(output_dir, exist_ok=True)
|
| 179 |
|
|
|
|
| 189 |
logging_steps=training_config.get("logging_steps", 10),
|
| 190 |
save_steps=training_config.get("save_steps", 100),
|
| 191 |
save_total_limit=training_config.get("save_total_limit", 2),
|
| 192 |
+
bf16=True,
|
| 193 |
fp16=False,
|
| 194 |
gradient_checkpointing=training_config.get("gradient_checkpointing", True),
|
| 195 |
evaluation_strategy="steps" if eval_dataset else "no",
|