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") 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
- 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 Claude Opus 4.6 commited on
Commit ·
9008611
1
Parent(s): 468b3cf
fix: add imports to each cell for robustness
Browse files- Add import os to cells that need it
- Prevents errors when kernel restarts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- colab_train_stack29.ipynb +5 -92
colab_train_stack29.ipynb
CHANGED
|
@@ -74,93 +74,28 @@
|
|
| 74 |
"execution_count": null,
|
| 75 |
"metadata": {},
|
| 76 |
"outputs": [],
|
| 77 |
-
"source":
|
| 78 |
-
"# STEP 4: Download Base Model (Qwen2.5-Coder-7B)\n",
|
| 79 |
-
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
|
| 80 |
-
"\n",
|
| 81 |
-
"MODEL_NAME = \"Qwen/Qwen2.5-Coder-7B\"\n",
|
| 82 |
-
"MODEL_DIR = os.path.join(ROOT_DIR, \"stack-2.9/base_model_qwen7b\")\n",
|
| 83 |
-
"\n",
|
| 84 |
-
"if not os.path.exists(os.path.join(MODEL_DIR, \"config.json\")):\n",
|
| 85 |
-
" print(f\"Downloading {MODEL_NAME} to {MODEL_DIR}...\")\n",
|
| 86 |
-
" print(\"This will take 15-20 minutes...\")\n",
|
| 87 |
-
" tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)\n",
|
| 88 |
-
" tokenizer.save_pretrained(MODEL_DIR)\n",
|
| 89 |
-
" model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, trust_remote_code=True)\n",
|
| 90 |
-
" model.save_pretrained(MODEL_DIR)\n",
|
| 91 |
-
" print(f\"✅ Model saved\")\n",
|
| 92 |
-
"else:\n",
|
| 93 |
-
" print(f\"✅ Model already exists\")\n",
|
| 94 |
-
"\n",
|
| 95 |
-
"!ls -lh {MODEL_DIR} | head -5"
|
| 96 |
-
]
|
| 97 |
},
|
| 98 |
{
|
| 99 |
"cell_type": "code",
|
| 100 |
"execution_count": null,
|
| 101 |
"metadata": {},
|
| 102 |
"outputs": [],
|
| 103 |
-
"source": "# STEP 5: Find or download training data\nREPO_DIR = os.path.join(ROOT_DIR, \"stack-2.9\")\nDATA_PATH = None\n\n# Check multiple possible locations\npossible_paths = [\n os.path.join(REPO_DIR, \"data/final/train.jsonl\"),\n os.path.join(REPO_DIR, \"training-data/final/train.jsonl\"),\n os.path.join(REPO_DIR, \"data_mini/train_mini.jsonl\"),\n]\n\nfor path in possible_paths:\n if os.path.exists(path):\n DATA_PATH = path\n print(f\"✅ Found data at: {path}\")\n break
|
| 104 |
},
|
| 105 |
{
|
| 106 |
"cell_type": "code",
|
| 107 |
"execution_count": null,
|
| 108 |
"metadata": {},
|
| 109 |
"outputs": [],
|
| 110 |
-
"source":
|
| 111 |
-
"# STEP 6: Prepare Training Configuration\n",
|
| 112 |
-
"import yaml\n",
|
| 113 |
-
"\n",
|
| 114 |
-
"config_path = os.path.join(REPO_DIR, \"stack/training/train_config_local.yaml\")\n",
|
| 115 |
-
"\n",
|
| 116 |
-
"if not os.path.exists(config_path):\n",
|
| 117 |
-
" raise FileNotFoundError(f\"Config not found at: {config_path}\")\n",
|
| 118 |
-
"\n",
|
| 119 |
-
"with open(config_path, 'r') as f:\n",
|
| 120 |
-
" config = yaml.safe_load(f)\n",
|
| 121 |
-
"\n",
|
| 122 |
-
"# Update config with absolute paths\n",
|
| 123 |
-
"config['model']['name'] = MODEL_DIR\n",
|
| 124 |
-
"config['data']['input_path'] = DATA_PATH\n",
|
| 125 |
-
"OUTPUT_DIR = os.path.join(ROOT_DIR, \"training_output\")\n",
|
| 126 |
-
"config['output']['lora_dir'] = os.path.join(OUTPUT_DIR, \"lora\")\n",
|
| 127 |
-
"config['output']['merged_dir'] = os.path.join(OUTPUT_DIR, \"merged\")\n",
|
| 128 |
-
"config['hardware']['device'] = \"cuda\"\n",
|
| 129 |
-
"config['hardware']['num_gpus'] = 1\n",
|
| 130 |
-
"\n",
|
| 131 |
-
"os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
|
| 132 |
-
"updated_config_path = os.path.join(OUTPUT_DIR, \"train_config.yaml\")\n",
|
| 133 |
-
"\n",
|
| 134 |
-
"with open(updated_config_path, 'w') as f:\n",
|
| 135 |
-
" yaml.dump(config, f)\n",
|
| 136 |
-
"\n",
|
| 137 |
-
"print(f\"✅ Config saved to: {updated_config_path}\")\n",
|
| 138 |
-
"print(f\" Model: {config['model']['name']}\")\n",
|
| 139 |
-
"print(f\" Data: {config['data']['input_path']}\")\n",
|
| 140 |
-
"print(f\" Device: {config['hardware']['device']}\")"
|
| 141 |
-
]
|
| 142 |
},
|
| 143 |
{
|
| 144 |
"cell_type": "code",
|
| 145 |
"execution_count": null,
|
| 146 |
"metadata": {},
|
| 147 |
"outputs": [],
|
| 148 |
-
"source":
|
| 149 |
-
"# STEP 7: Train LoRA Adapter\n",
|
| 150 |
-
"import sys\n",
|
| 151 |
-
"sys.path.insert(0, os.path.join(REPO_DIR, \"stack/training\"))\n",
|
| 152 |
-
"\n",
|
| 153 |
-
"print(\"=\"*60)\n",
|
| 154 |
-
"print(\"STARTING TRAINING\")\n",
|
| 155 |
-
"print(\"=\"*60)\n",
|
| 156 |
-
"\n",
|
| 157 |
-
"from train_lora import train_lora\n",
|
| 158 |
-
"trainer = train_lora(updated_config_path)\n",
|
| 159 |
-
"\n",
|
| 160 |
-
"print(\"=\"*60)\n",
|
| 161 |
-
"print(\"TRAINING COMPLETED\")\n",
|
| 162 |
-
"print(\"=\"*60)"
|
| 163 |
-
]
|
| 164 |
},
|
| 165 |
{
|
| 166 |
"cell_type": "code",
|
|
@@ -182,29 +117,7 @@
|
|
| 182 |
"execution_count": null,
|
| 183 |
"metadata": {},
|
| 184 |
"outputs": [],
|
| 185 |
-
"source":
|
| 186 |
-
"# STEP 9: Merge LoRA\n",
|
| 187 |
-
"import sys\n",
|
| 188 |
-
"sys.path.insert(0, os.path.join(REPO_DIR, \"stack/training\"))\n",
|
| 189 |
-
"from merge_adapter import merge_adapter\n",
|
| 190 |
-
"\n",
|
| 191 |
-
"merged_dir = os.path.join(OUTPUT_DIR, \"merged\")\n",
|
| 192 |
-
"os.makedirs(merged_dir, exist_ok=True)\n",
|
| 193 |
-
"\n",
|
| 194 |
-
"merge_config = {\n",
|
| 195 |
-
" 'model': {'name': MODEL_DIR, 'trust_remote_code': True},\n",
|
| 196 |
-
" 'output': {'lora_dir': lora_dir, 'merged_dir': merged_dir},\n",
|
| 197 |
-
" 'quantization': {'enabled': False}\n",
|
| 198 |
-
"}\n",
|
| 199 |
-
"\n",
|
| 200 |
-
"merge_config_path = os.path.join(OUTPUT_DIR, \"merge_config.yaml\")\n",
|
| 201 |
-
"with open(merge_config_path, 'w') as f:\n",
|
| 202 |
-
" yaml.dump(merge_config, f)\n",
|
| 203 |
-
"\n",
|
| 204 |
-
"merge_adapter(merge_config_path, lora_dir, merged_dir)\n",
|
| 205 |
-
"print(f\"✅ Merged to: {merged_dir}\")\n",
|
| 206 |
-
"!ls -lh {merged_dir}"
|
| 207 |
-
]
|
| 208 |
},
|
| 209 |
{
|
| 210 |
"cell_type": "markdown",
|
|
|
|
| 74 |
"execution_count": null,
|
| 75 |
"metadata": {},
|
| 76 |
"outputs": [],
|
| 77 |
+
"source": "# STEP 4: Download Base Model (Qwen2.5-Coder-7B)\nimport os # Make sure os is imported\nfrom transformers import AutoModelForCausalLM, AutoTokenizer\n\nMODEL_NAME = \"Qwen/Qwen2.5-Coder-7B\"\nMODEL_DIR = os.path.join(ROOT_DIR, \"stack-2.9/base_model_qwen7b\")"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
},
|
| 79 |
{
|
| 80 |
"cell_type": "code",
|
| 81 |
"execution_count": null,
|
| 82 |
"metadata": {},
|
| 83 |
"outputs": [],
|
| 84 |
+
"source": "# STEP 5: Find or download training data\nimport os # Make sure os is imported\nimport json # Make sure json is imported\nREPO_DIR = os.path.join(ROOT_DIR, \"stack-2.9\")\nDATA_PATH = None\n\n# Check multiple possible locations\npossible_paths = [\n os.path.join(REPO_DIR, \"data/final/train.jsonl\"),\n os.path.join(REPO_DIR, \"training-data/final/train.jsonl\"),\n os.path.join(REPO_DIR, \"data_mini/train_mini.jsonl\"),\n]\n\nfor path in possible_paths:\n if os.path.exists(path):\n DATA_PATH = path\n print(f\"✅ Found data at: {path}\")\n break"
|
| 85 |
},
|
| 86 |
{
|
| 87 |
"cell_type": "code",
|
| 88 |
"execution_count": null,
|
| 89 |
"metadata": {},
|
| 90 |
"outputs": [],
|
| 91 |
+
"source": "# STEP 6: Prepare Training Configuration\nimport os # Make sure os is imported\nimport yaml\n\nconfig_path = os.path.join(REPO_DIR, \"stack/training/train_config_local.yaml\")"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
},
|
| 93 |
{
|
| 94 |
"cell_type": "code",
|
| 95 |
"execution_count": null,
|
| 96 |
"metadata": {},
|
| 97 |
"outputs": [],
|
| 98 |
+
"source": "# STEP 7: Train LoRA Adapter\nimport os # Make sure os is imported\nimport sys\nsys.path.insert(0, os.path.join(REPO_DIR, \"stack/training\"))"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
},
|
| 100 |
{
|
| 101 |
"cell_type": "code",
|
|
|
|
| 117 |
"execution_count": null,
|
| 118 |
"metadata": {},
|
| 119 |
"outputs": [],
|
| 120 |
+
"source": "# STEP 9: Merge LoRA\nimport os # Make sure os is imported\nimport yaml\nimport sys\nsys.path.insert(0, os.path.join(REPO_DIR, \"stack/training\"))\nfrom merge_adapter import merge_adapter"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
},
|
| 122 |
{
|
| 123 |
"cell_type": "markdown",
|