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
| #!/usr/bin/env python3 | |
| """ | |
| Combine all training data sources into final dataset. | |
| Applies deduplication and quality filtering. | |
| """ | |
| import json | |
| import hashlib | |
| from pathlib import Path | |
| import argparse | |
| from datetime import datetime | |
| def hash_messages(messages: list) -> str: | |
| """Create a hash of messages to detect duplicates.""" | |
| m = hashlib.md5() | |
| m.update(json.dumps(messages, sort_keys=True).encode()) | |
| return m.hexdigest() | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--output", type=str, default="training-data/final/dataset.jsonl") | |
| parser.add_argument("--train-size", type=float, default=0.8) | |
| parser.add_argument("--val-size", type=float, default=0.1) | |
| parser.add_argument("--max-dataset", type=int, default=50000, help="Max examples to include") | |
| args = parser.parse_args() | |
| output_path = Path(args.output) | |
| output_path.parent.mkdir(parents=True, exist_ok=True) | |
| # List all source files | |
| sources = [ | |
| ("training-data/synthetic/examples.jsonl", "original_synthetic"), | |
| ("training-data/advanced-patterns/examples.jsonl", "advanced_patterns"), | |
| ("training-data/code-pairs/pairs.json", "code_pairs"), | |
| ("training-data/code-pairs/extended_pairs.json", "code_pairs_extended"), | |
| ("training-data/scaled/synthetic_final.jsonl", "synthetic_augmented"), | |
| ("training-data/scaled/random_10k.jsonl", "random_10k"), | |
| ("training-data/scaled/random_5_5k.jsonl", "random_5k"), | |
| ] | |
| all_examples = [] | |
| seen_hashes = set() | |
| duplicates_removed = 0 | |
| print("📦 Combining datasets...") | |
| for file_path, source in sources: | |
| path = Path(file_path) | |
| if not path.exists(): | |
| print(f" ⚠️ Not found: {path}") | |
| continue | |
| print(f" Loading {source}...") | |
| count = 0 | |
| with open(path, 'r') as f: | |
| for line in f: | |
| try: | |
| ex = json.loads(line) | |
| # Convert code-pair format if needed | |
| if "code" in ex and "comment" in ex: | |
| # Convert code-pair to message format | |
| ex = { | |
| "messages": [ | |
| {"role": "user", "content": ex["comment"]}, | |
| {"role": "assistant", "content": f"Here's the code:\n{ex['code']}"} | |
| ], | |
| "source": source, | |
| "type": "code_pair" | |
| } | |
| # Deduplication | |
| msg_hash = hash_messages(ex["messages"]) | |
| if msg_hash in seen_hashes: | |
| duplicates_removed += 1 | |
| continue | |
| seen_hashes.add(msg_hash) | |
| # Add metadata | |
| ex["source_original"] = source | |
| all_examples.append(ex) | |
| count += 1 | |
| if len(all_examples) >= args.max_dataset: | |
| break | |
| except json.JSONDecodeError: | |
| continue | |
| print(f" ✅ Added {count} examples") | |
| print(f"\n✨ Total collected: {len(all_examples)} examples") | |
| print(f" Duplicates removed: {duplicates_removed}") | |
| # Shuffle | |
| random.seed(42) | |
| random.shuffle(all_examples) | |
| # Split | |
| n_total = len(all_examples) | |
| n_train = int(n_total * args.train_size) | |
| n_val = int(n_total * args.val_size) | |
| n_test = n_total - n_train - n_val | |
| train_set = all_examples[:n_train] | |
| val_set = all_examples[n_train:n_train+n_val] | |
| test_set = all_examples[n_train+n_val:] | |
| print(f"\n📊 Split:") | |
| print(f" Train: {len(train_set)}") | |
| print(f" Val: {len(val_set)}") | |
| print(f" Test: {len(test_set)}") | |
| # Save splits | |
| for split_name, split_data in [("train", train_set), ("val", val_set), ("test", test_set)]: | |
| split_path = output_path.parent / f"{split_name}.jsonl" | |
| with open(split_path, 'w') as f: | |
| for ex in split_data: | |
| f.write(json.dumps(ex) + "\n") | |
| print(f" Saved {split_name} to {split_path}") | |
| # Create manifest | |
| manifest = { | |
| "dataset": "Stack 2.9 Training Data", | |
| "version": "1.0", | |
| "created": datetime.now().isoformat(), | |
| "total_examples": n_total, | |
| "splits": { | |
| "train": len(train_set), | |
| "val": len(val_set), | |
| "test": len(test_set) | |
| }, | |
| "sources": {src: sum(1 for ex in all_examples if ex.get("source_original") == src) for src in set(ex.get("source_original") for ex in all_examples)} | |
| } | |
| manifest_path = output_path.parent / "manifest.json" | |
| with open(manifest_path, 'w') as f: | |
| json.dump(manifest, f, indent=2) | |
| print(f"\n📄 Manifest: {manifest_path}") | |
| print("\n✅ Dataset complete!") | |
| if __name__ == "__main__": | |
| import random | |
| main() |