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 Β·
f90ca5c
1
Parent(s): 9008611
fix: define all paths in first cell for kernel restart safety
Browse files- Define ROOT_DIR, REPO_DIR, MODEL_DIR, OUTPUT_DIR in cell 1
- All other cells now use these pre-defined variables
- Prevents NameError when kernel restarts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- colab_train_stack29.ipynb +5 -30
colab_train_stack29.ipynb
CHANGED
|
@@ -23,39 +23,14 @@
|
|
| 23 |
"execution_count": null,
|
| 24 |
"metadata": {},
|
| 25 |
"outputs": [],
|
| 26 |
-
"source":
|
| 27 |
-
"# STEP 1: Setup - Mount Drive and define root directory\n",
|
| 28 |
-
"from google.colab import drive\n",
|
| 29 |
-
"drive.mount('/content/drive')\n",
|
| 30 |
-
"\n",
|
| 31 |
-
"import os\n",
|
| 32 |
-
"ROOT_DIR = \"/content/drive/MyDrive/stack-2.9\"\n",
|
| 33 |
-
"os.makedirs(ROOT_DIR, exist_ok=True)\n",
|
| 34 |
-
"os.chdir(ROOT_DIR)\n",
|
| 35 |
-
"\n",
|
| 36 |
-
"print(f\"β
Working directory: {os.getcwd()}\")\n",
|
| 37 |
-
"!ls -la"
|
| 38 |
-
]
|
| 39 |
},
|
| 40 |
{
|
| 41 |
"cell_type": "code",
|
| 42 |
"execution_count": null,
|
| 43 |
"metadata": {},
|
| 44 |
"outputs": [],
|
| 45 |
-
"source":
|
| 46 |
-
"# STEP 2: Clone repo (fresh every time)\n",
|
| 47 |
-
"import shutil\n",
|
| 48 |
-
"\n",
|
| 49 |
-
"if os.path.exists('stack-2.9'):\n",
|
| 50 |
-
" print(\"Removing old stack-2.9...\")\n",
|
| 51 |
-
" shutil.rmtree('stack-2.9')\n",
|
| 52 |
-
"\n",
|
| 53 |
-
"!git clone https://github.com/my-ai-stack/stack-2.9.git\n",
|
| 54 |
-
"\n",
|
| 55 |
-
"os.chdir(os.path.join(ROOT_DIR, 'stack-2.9'))\n",
|
| 56 |
-
"print(f\"β
In: {os.getcwd()}\")\n",
|
| 57 |
-
"!ls -la"
|
| 58 |
-
]
|
| 59 |
},
|
| 60 |
{
|
| 61 |
"cell_type": "code",
|
|
@@ -74,21 +49,21 @@
|
|
| 74 |
"execution_count": null,
|
| 75 |
"metadata": {},
|
| 76 |
"outputs": [],
|
| 77 |
-
"source": "# STEP 4: Download Base Model (Qwen2.5-Coder-7B)\
|
| 78 |
},
|
| 79 |
{
|
| 80 |
"cell_type": "code",
|
| 81 |
"execution_count": null,
|
| 82 |
"metadata": {},
|
| 83 |
"outputs": [],
|
| 84 |
-
"source": "# STEP 5: Find or download training data\nimport
|
| 85 |
},
|
| 86 |
{
|
| 87 |
"cell_type": "code",
|
| 88 |
"execution_count": null,
|
| 89 |
"metadata": {},
|
| 90 |
"outputs": [],
|
| 91 |
-
"source": "# STEP 6: Prepare Training Configuration\nimport os
|
| 92 |
},
|
| 93 |
{
|
| 94 |
"cell_type": "code",
|
|
|
|
| 23 |
"execution_count": null,
|
| 24 |
"metadata": {},
|
| 25 |
"outputs": [],
|
| 26 |
+
"source": "# STEP 1: Setup - Mount Drive and define root directory\nfrom google.colab import drive\ndrive.mount('/content/drive')\n\nimport os\nROOT_DIR = \"/content/drive/MyDrive/stack-2.9\"\nos.makedirs(ROOT_DIR, exist_ok=True)\nos.chdir(ROOT_DIR)\n\n# Define all paths once\nREPO_DIR = os.path.join(ROOT_DIR, \"stack-2.9\")\nMODEL_DIR = os.path.join(REPO_DIR, \"base_model_qwen7b\")\nOUTPUT_DIR = os.path.join(ROOT_DIR, \"training_output\")\n\nprint(f\"β
ROOT_DIR: {ROOT_DIR}\")\nprint(f\"β
REPO_DIR: {REPO_DIR}\")\nprint(f\"β
MODEL_DIR: {MODEL_DIR}\")\nprint(f\"β
OUTPUT_DIR: {OUTPUT_DIR}\")\n!ls -la"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
},
|
| 28 |
{
|
| 29 |
"cell_type": "code",
|
| 30 |
"execution_count": null,
|
| 31 |
"metadata": {},
|
| 32 |
"outputs": [],
|
| 33 |
+
"source": "# STEP 2: Clone repo (fresh every time)\nimport shutil\n\nif os.path.exists('stack-2.9'):\n print(\"Removing old stack-2.9...\")\n shutil.rmtree('stack-2.9')\n\n!git clone https://github.com/my-ai-stack/stack-2.9.git\n\nos.chdir(REPO_DIR)\nprint(f\"β
In: {os.getcwd()}\")\n!ls -la"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
},
|
| 35 |
{
|
| 36 |
"cell_type": "code",
|
|
|
|
| 49 |
"execution_count": null,
|
| 50 |
"metadata": {},
|
| 51 |
"outputs": [],
|
| 52 |
+
"source": "# STEP 4: Download Base Model (Qwen2.5-Coder-7B)\nfrom transformers import AutoModelForCausalLM, AutoTokenizer\n\nMODEL_NAME = \"Qwen/Qwen2.5-Coder-7B\"\n\nif not os.path.exists(os.path.join(MODEL_DIR, \"config.json\")):\n print(f\"Downloading {MODEL_NAME} to {MODEL_DIR}...\")\n print(\"This will take 15-20 minutes...\")\n tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)\n tokenizer.save_pretrained(MODEL_DIR)\n model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, trust_remote_code=True)\n model.save_pretrained(MODEL_DIR)\n print(f\"β
Model saved\")\nelse:\n print(f\"β
Model already exists\")\n\n!ls -lh {MODEL_DIR} | head -5"
|
| 53 |
},
|
| 54 |
{
|
| 55 |
"cell_type": "code",
|
| 56 |
"execution_count": null,
|
| 57 |
"metadata": {},
|
| 58 |
"outputs": [],
|
| 59 |
+
"source": "# STEP 5: Find or download training data\nimport json\n\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"
|
| 60 |
},
|
| 61 |
{
|
| 62 |
"cell_type": "code",
|
| 63 |
"execution_count": null,
|
| 64 |
"metadata": {},
|
| 65 |
"outputs": [],
|
| 66 |
+
"source": "# STEP 6: Prepare Training Configuration\nimport yaml\n\nconfig_path = os.path.join(REPO_DIR, \"stack/training/train_config_local.yaml\")\n\nif not os.path.exists(config_path):\n raise FileNotFoundError(f\"Config not found at: {config_path}\")\n\nwith open(config_path, 'r') as f:\n config = yaml.safe_load(f)\n\n# Update config with absolute paths\nconfig['model']['name'] = MODEL_DIR\nconfig['data']['input_path'] = DATA_PATH\nconfig['output']['lora_dir'] = os.path.join(OUTPUT_DIR, \"lora\")\nconfig['output']['merged_dir'] = os.path.join(OUTPUT_DIR, \"merged\")\nconfig['hardware']['device'] = \"cuda\"\nconfig['hardware']['num_gpus'] = 1\n\nos.makedirs(OUTPUT_DIR, exist_ok=True)\nupdated_config_path = os.path.join(OUTPUT_DIR, \"train_config.yaml\")\n\nwith open(updated_config_path, 'w') as f:\n yaml.dump(config, f)\n\nprint(f\"β
Config saved to: {updated_config_path}\")\nprint(f\" Model: {config['model']['name']}\")\nprint(f\" Data: {config['data']['input_path']}\")"
|
| 67 |
},
|
| 68 |
{
|
| 69 |
"cell_type": "code",
|