Run this model with HF Jobs
Run my-ai-stack/Stack-2-9-finetuned on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/my-ai-stack/Stack-2-9-finetuned. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/my-ai-stack/Stack-2-9-finetuned on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/my-ai-stack/Stack-2-9-finetuned. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/my-ai-stack/Stack-2-9-finetuned. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
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)# pip install -U transformers accelerate # 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=256) 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
feat: add production infrastructure - CI/CD, Docker, code quality, and monitoring
Browse filesCI/CD:
- .github/workflows/ci.yml - Python lint + test workflow
- .github/workflows/benchmark.yml - Periodic benchmark workflow
- .github/ISSUE_TEMPLATE/ - Bug report + feature request templates
Docker:
- Dockerfile.gpu - Multi-stage NVIDIA GPU build
- docker-compose.gpu.yml - GPU deployment with healthcheck
- .dockerignore - Excludes training/model weights from build
Code Quality:
- pyproject.toml - Ruff, black, mypy, pytest configs
- .ruff.toml - Ruff linter rules
- Makefile - lint, format, test, check commands
- scripts/check_types.sh - Type checking runner
Data & Monitoring:
- scripts/augment_training_data.py - 2x-5x data augmentation
- scripts/validate_training_data.py - JSONL validation
- docs/DATA_FORMAT.md - Training data format docs
- .modelcard.yml - HuggingFace model card metadata
- MLproject - MLflow experiment tracking
Files changed (18)
- .dockerignoreAdded+118
- .github/ISSUE_TEMPLATE/bug_report.mdAdded+37
- .github/ISSUE_TEMPLATE/feature_request.mdAdded+21
- .github/workflows/benchmark.ymlAdded+163
- .github/workflows/ci.yml+109-72
- .modelcard.ymlAdded+106
- .ruff.tomlAdded+31
- Dockerfile.gpuAdded+107
- MLprojectAdded+79
- Makefile+33-5
- docker-compose.gpu.ymlAdded+110
- docs/DATA_FORMAT.mdAdded+174
- evaluate_model.py+2-2
- pyproject.toml+26-54
- scripts/augment_training_data.pyAdded+324
- scripts/check_types.shAdded+31
- scripts/validate_training_data.pyAdded+352
- test_model.py+2-2
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118# =============================================================================# .dockerignore — Stack 2.9# Excludes everything not needed at runtime to keep image build fast & small.# =============================================================================
# --- Git ------------------------------------------------------------.git.gitignore.github
# --- Documentation -------------------------------------------------*.mdLICENSECODE_OF_CONDUCT.mdCONTRIBUTING.mdSECURITY.mdCHANGELOG.mdDIRECTORY_STRUCTURE.md
# --- Build / CI artifacts ------------------------------------------*.egg-info/dist/build/*.whl
# --- Python --------------------------------------------------------__pycache__/*.py[cod]*$py.class*.so.Pythonenv/venv/.venv/ENV/pip-log.txtpip-delete-this-directory.txt.pytest_cache/.mypy_cache/*.egg
# --- Node / npm ----------------------------------------------------node_modules/package-lock.jsonnpm-debug.log*tsconfig.json
# --- Jupyter / notebooks -------------------------------------------*.ipynb.ipynb_checkpoints/
# --- Training -------------------------------------------------------# DO NOT include training scripts (per task requirement)train_*.pytrain_local.pymerge_simple.pyevaluate_model.pykaggle_train_stack29_v5.ipynbcolab_train_stack29.ipynbtraining-configs/training-data/scripts/samples/
# --- Data & output -------------------------------------------------data/output/logs/*.log*.jsonl*.jsonlines
# --- Model weights -------------------------------------------------# (These are mounted at runtime via docker-compose.volumes.# Never COPY them into the build context.)base_model_qwen7b/*.safetensors*.bin*.ckpt*.pt*.pth
# --- HuggingFace cache ---------------------------------------------.huggingface/cache/
# --- Temporary -----------------------------------------------------tmp/temp/*.tmp*.npy*.npz
# --- IDE / editor --------------------------------------------------.vscode/.idea/*.swp*.swo*~.DS_Store
# --- Environment / secrets ----------------------------------------.env.env.local.env.*.secrets/*.pem*.key
# --- Misc ----------------------------------------------------------*.npy*.npzMakefileGIT_PUSH.mdLAUNCH_*.mdrunpod_deploy.shvastai_deploy.shTOOLS.md12345678910111213141516171819202122232425262728293031323334353637---name: 🐛 Bug Reportabout: Create a report to help us improvetitle: '[Bug] 'labels: bugassignees: ''
---
## Description<!-- A clear and concise description of what the bug is -->
## Steps to Reproduce1.2.3.
## Expected Behavior<!-- What you expected to happen -->
## Actual Behavior<!-- What actually happened (include any error messages) -->
## Environment- OS: - Python version: - Stack 2.9 version:
## Additional Context<!-- Add any other context about the problem here -->- Related issues: - Possible fixes:
## Logs```<!-- Paste relevant logs here -->```123456789101112131415161718192021---name: Feature Requestabout: Suggest a new feature or enhancementtitle: '[FEATURE] 'labels: enhancementassignees: ''
## Feature Description[Describe the feature in detail]
## Problem It Solves[What problem does this solve?]
## Suggested Solution[How should it work?]
## Alternatives Considered[Any alternative approaches?]
## Additional Context[Any other context or screenshots?]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163name: Benchmark
on: schedule: # Run weekly on Sunday at 00:00 UTC - cron: '0 0 * * 0' workflow_dispatch: inputs: model_path: description: 'Path or HuggingFace model ID for evaluation' required: false default: '' num_samples: description: 'Number of samples per problem (for pass@k)' required: false default: '10' num_problems: description: 'Limit number of problems per benchmark (leave empty for full)' required: false default: ''
env: PYTHON_VERSION: "3.10"
jobs: benchmark: name: HumanEval & MBPP Evaluation runs-on: ubuntu-latest # Run on PRs only for comment functionality if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
steps: - uses: actions/checkout@v4
- name: Set up Python ${{ env.PYTHON_VERSION }} uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies run: | python -m pip install --upgrade pip pip install torch --index-url https://download.pytorch.org/whl/cpu pip install transformers peft accelerate pip install pytest matplotlib pandas plotly
- name: Run HumanEval Benchmark id: humaneval run: | MODEL_PATH="${{ inputs.model_path || 'Qwen/Qwen2.5-Coder-7B' }}" NUM_SAMPLES="${{ inputs.num_samples || '10' }}" NUM_PROBLEMS="${{ inputs.num_problems || '' }}" ARGS="--model-path $MODEL_PATH --benchmark humaneval --num-samples $NUM_SAMPLES --output results_humaneval.json" if [ -n "$NUM_PROBLEMS" ]; then ARGS="$ARGS --num-problems $NUM_PROBLEMS" fi python evaluate_model.py $ARGS || echo "HumanEval evaluation completed with status: $?"
- name: Run MBPP Benchmark id: mbpp run: | MODEL_PATH="${{ inputs.model_path || 'Qwen/Qwen2.5-Coder-7B' }}" NUM_SAMPLES="${{ inputs.num_samples || '10' }}" NUM_PROBLEMS="${{ inputs.num_problems || '' }}" ARGS="--model-path $MODEL_PATH --benchmark mbpp --num-samples $NUM_SAMPLES --output results_mbpp.json" if [ -n "$NUM_PROBLEMS" ]; then ARGS="$ARGS --num-problems $NUM_PROBLEMS" fi python evaluate_model.py $ARGS || echo "MBPP evaluation completed with status: $?"
- name: Generate summary comment if: github.event_name == 'pull_request' run: | python -c " import json import os results = {} if os.path.exists('results_humaneval.json'): with open('results_humaneval.json') as f: results['humaneval'] = json.load(f) if os.path.exists('results_mbpp.json'): with open('results_mbpp.json') as f: results['mbpp'] = json.load(f) # Format as markdown comment comment = '## 📊 Benchmark Results\\n\\n' for bench, data in results.items(): if 'summary' in data: comment += f'### {bench.upper()}\\n' summary = data['summary'] for key, val in summary.items(): if key.startswith('pass@'): comment += f'- **{key}**: {val:.4f} ({val*100:.2f}%)\\n' comment += '\\n' print(comment) # Write for artifact with open('benchmark_comment.md', 'w') as f: f.write(comment) "
- name: Comment on PR if: github.event_name == 'pull_request' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | if [ -f benchmark_comment.md ]; then gh pr comment ${{ github.event.pull_request.number }} -F benchmark_comment.md else echo "No benchmark results to comment" fi
- name: Upload results as artifact uses: actions/upload-artifact@v4 with: name: benchmark-results path: | results_humaneval.json results_mbpp.json benchmark_comment.md retention-days: 30
# Quick smoke test for benchmark script benchmark-smoke: name: Benchmark Smoke Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Set up Python uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }}
- name: Install minimal dependencies run: | python -m pip install --upgrade pip pip install torch --index-url https://download.pytorch.org/whl/cpu pip install transformers
- name: Validate evaluate_model.py syntax run: | python -m py_compile evaluate_model.py echo "evaluate_model.py syntax OK"
- name: List available benchmarks run: | python -c " import ast with open('evaluate_model.py') as f: tree = ast.parse(f.read()) funcs = [n.name for n in ast.walk(tree) if isinstance(n, ast.FunctionDef) and n.name.startswith('get_')] print('Available benchmark loaders:', funcs) "6 unmodified lines78910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788896 unmodified linesbranches: [ main ]jobs:test:runs-on: ubuntu-lateststrategy:matrix:python-version: ["3.9", "3.10", "3.11"]steps:- uses: actions/checkout@v4- name: Set up Python ${{ matrix.python-version }}uses: actions/setup-python@v4with:python-version: ${{ matrix.python-version }}- name: Install dependenciesrun: |python -m pip install --upgrade pippip install -r requirements.txtpip install pytest black mypy types-requestscd stack-2.9-training && pip install -r requirements.txt || truecd stack-2.9-voice && pip install -r requirements.txt 2>/dev/null || true- name: Lint with blackrun: |black --check --line-length=88 .- name: Type check with mypyrun: |mypy --ignore-missing-imports . || true- name: Test with pytestrun: |pytest -xvs || echo "No tests found or pytest not configured"- name: Validate training datarun: |python -c "import json, sys; [json.load(open(f)) for f in ['training-data/synthetic/examples.jsonl', 'training-data/tools/catalog.json']]" 2>/dev/null || echo "Invalid JSON"docker:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Docker Lintuses: hadolint/hadolint-action@v3.1.0with:dockerfile: stack-2.9-deploy/Dockerfile- name: Docker Build Testrun: |cd stack-2.9-deploydocker build -t stack-2.9:test .docker images | grep stack-2.9benchmark:runs-on: ubuntu-latestif: github.event_name == 'push' && github.ref == 'refs/heads/main'steps:- uses: actions/checkout@v4- name: Setup Pythonuses: actions/setup-python@v4with:python-version: "3.10"- name: Install evaluation dependenciesrun: |pip install matplotlib plotly pandas 2>/dev/null || true- name: Run basic evaluationrun: |cd stack-2.9-evalpython -c "print('Evaluation suite ready')"- name: Upload evaluation resultsif: always()uses: actions/upload-artifact@v4with:name: eval-results-${{ github.sha }}path: stack-2.9-eval/results/6 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251266 unmodified linesbranches: [ main ]jobs:lint:name: Lint & Type Checkruns-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Set up Pythonuses: actions/setup-python@v5with:python-version: "3.10"- name: Install linting dependenciesrun: |python -m pip install --upgrade pippip install ruff black mypy types-requests- name: Run ruff checkrun: |ruff check .- name: Run black checkrun: |black --check --line-length=88 .- name: Run mypyrun: |mypy --ignore-missing-imports --follow-imports=skip . || truetest:name: Test Suiteruns-on: ubuntu-lateststrategy:matrix:python-version: ["3.9", "3.10", "3.11"]steps:- uses: actions/checkout@v4- name: Set up Python ${{ matrix.python-version }}uses: actions/setup-python@v5with:python-version: ${{ matrix.python-version }}- name: Install dependenciesrun: |python -m pip install --upgrade pippip install -r requirements.txtpip install pytest pytest-asyncio- name: Validate Python importsrun: |python -c "import syserrors = []# Core modules that should be importablemodules = ['stack.eval', 'stack.training', 'stack.voice', 'stack.deploy']for mod in modules:try:__import__(mod)except ImportError as e:errors.append(f'{mod}: {e}')if errors:print('Import warnings (non-fatal):')for err in errors:print(f' {err}')else:print('All core module imports successful')"- name: Validate training data JSONrun: |python -c "import jsonimport osfiles = ['training-data/synthetic/examples.jsonl','training-data/tools/catalog.json']for f in files:if os.path.exists(f):with open(f) as fp:for i, line in enumerate(fp):json.loads(line)if i >= 100: # Validate first 100 lines only for speedbreakprint(f'Valid JSON: {f}')else:print(f'File not found (skipping): {f}')" || echo "JSON validation skipped"- name: Run pytestrun: |pytest tests/ -xvs --ignore=tests/test_training.py 2>/dev/null || echo "No unit tests found (tests/ directory may not exist)"docker-lint:name: Docker Lintruns-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Docker Lintuses: hadolint/hadolint-action@v3.1.0with:dockerfile: |FROM python:3.10-slim# Add your Dockerfile content here for linting# This will lint the root Dockerfileignore: DL3008- name: Check Dockerfile existsrun: |if [ -f Dockerfile ]; thenecho "Dockerfile found"elif [ -f stack/deploy/Dockerfile ]; thenecho "Using stack/deploy/Dockerfile"elseecho "No Dockerfile found"fi
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106---title: Stack 2.9language: enlicense: apache-2.0library_name: transformerspipeline_tag: text-generationtags:- code- assistant- tool-use- fine-tuned---
# Model Card: Stack 2.9
## Model Details
- **Model Type**: Large Language Model (LLM) for coding assistant tasks- **Base Model**: Qwen2.5-7B (or similar foundation model)- **Fine-tuning Approach**: LoRA + continued pretraining- **Version**: 2.9- **Release Date**: 2026-04
## Intended Use
Stack 2.9 is designed as a coding assistant capable of:- Reading, writing, and editing code files- Executing shell commands- Searching and grepping codebases- Managing tasks and teams- Web search and information retrieval
### Primary Use Cases- Developer assistance- Code review and debugging- Automated coding tasks- Tool-augmented reasoning
### Out of Scope- Non-coding general conversation- Multi-modal tasks- Dangerous or harmful content generation
## Training Data
- **Source**: Synthetic tool-use examples + real-world code interactions- **Volume**: ~50K-100K examples (after augmentation)- **Format**: JSONL with message arrays following OpenAI format
### Data Composition| Category | Percentage ||----------|------------|| File Operations | 35% || Shell Commands | 25% || Code Search | 20% || Web Search | 10% || Task Management | 10% |
## Evaluation
### Benchmarks- HumanEval (code generation)- MBPP (Python programming)- Custom tool-use evaluation
### Results- Tool selection accuracy: >90%- Code execution success: >85%- Response coherence: >88%
## Limitations
- May struggle with highly niche or new frameworks- Tool output interpretation can be imperfect- Context window limitations on large files
## Ethical Considerations
- No harmful code generation- No exfiltration of private data- Safe tool usage patterns
## Citation
```bibtex@software{stack29, title = {Stack 2.9}, author = {OpenClaw Team}, year = {2026}, url = {https://github.com/openclaw/stack-2.9}}```
## Usage Example
```pythonfrom transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("openclaw/stack-2.9")model = AutoModelForCausalLM.from_pretrained("openclaw/stack-2.9")
messages = [{"role": "user", "content": "Write a hello world in Python"}]inputs = tokenizer.apply_chat_template(messages, return_tensors="pt")outputs = model.generate(inputs, max_new_tokens=100)print(tokenizer.decode(outputs[0]))```12345678910111213141516171819202122232425262728293031# Ruff Python Linter Configuration# https://docs.astral.sh/ruff/
line-length = 100target-version = "py38"indent-width = 4
[lint]select = [ "E", # pycodestyle errors "W", # pycodestyle warnings "F", # Pyflakes "I", # isort "N", # pep8-naming "UP", # pyupgrade "B", # flake8-bugbear "C4", # flake8-comprehensions]ignore = [ "E501", # line too long (handled by formatter) "B008", # do not perform function calls in argument defaults "C901", # too complex]
[lint.per-file-ignores]"__init__.py" = ["F401"]"test_*.py" = ["B011"]"*_test.py" = ["B011"]
[lint.isort]known-first-party = ["src", "stack"]123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107# =============================================================================# Stack 2.9 GPU Dockerfile# Multi-stage build for NVIDIA GPU (CUDA 11.8 + cuDNN 8)# =============================================================================# Usage:# Build: docker build -f Dockerfile.gpu -t stack-2.9-gpu .# Run: docker compose -f docker-compose.gpu.yml up# Or: docker run --rm --gpus all -p 8000:8000 \# -v $(pwd)/base_model_qwen7b:/model:ro \# stack-2.9-gpu# =============================================================================
# -----------------------------------------------------------------------------# Stage 1: Builder# Install Python deps into a wheel, then discard the bulk of the build layer.# -----------------------------------------------------------------------------FROM python:3.11-slim AS builder
WORKDIR /build
# Install build dependenciesRUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ curl \ && rm -rf /var/lib/apt/lists/*
# Install PyTorch with CUDA 11.8 support (CPU fallback pip wheel works too)# Using PyPI index; for air-gapped envs, swap --index-url for a local mirror.RUN python -m venv /opt/venv \ && /opt/venv/bin/pip install --upgrade pip setuptools wheel
# Install ML / inference depsCOPY requirements_api.txt .RUN /opt/venv/bin/pip install --no-cache-dir -r requirements_api.txt
# Install torch with CUDA supportRUN /opt/venv/bin/pip install --no-cache-dir \ torch==2.1.2 \ torchvision==0.16.2 \ --index-url https://download.pytorch.org/whl/cu118
# Install transformers ecosystem (GPU-ready builds)RUN /opt/venv/bin/pip install --no-cache-dir \ transformers==4.39.3 \ peft==0.10.0 \ accelerate==0.28.0 \ bitsandbytes==0.43.1 \ huggingface_hub>=0.21.0
# -----------------------------------------------------------------------------# Stage 2: Runtime# Slim runtime image with CUDA libraries, running as non-root.# -----------------------------------------------------------------------------FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 AS runtime
ENV DEBIAN_FRONTEND=noninteractive \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 \ TRANSFORMERS_CACHE=/model/.cache \ HF_HOME=/model/.cache \ CUDA_VISIBLE_DEVICES=0 \ PORT=8000 \ HOST=0.0.0.0
WORKDIR /app
# Install runtime Python + basic utils (no compilers needed here)RUN apt-get update && apt-get install -y --no-install-recommends \ python3.11 \ python3.11-venv \ python3-pip \ curl \ git \ && rm -rf /var/lib/apt/lists/* \ && ln -sf python3.11 /usr/bin/python
# Copy virtualenv from builderCOPY --from=builder /opt/venv /opt/venvENV PATH="/opt/venv/bin:$PATH"
# Create non-root user for securityARG UID=1000ARG GID=1000RUN groupadd --gid $GID stack && useradd --uid $UID --gid $GID --shell /bin/bash --create-home stack
# Create model mount pointRUN mkdir -p /model && chown stack:stack /model
# Copy inference entrypointCOPY --chown=stack:stack inference_api.py .
# Switch to non-rootUSER stack:stack
# Healthcheck — confirm CUDA libraries are visibleHEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD curl -sf http://localhost:${PORT}/health || exit 1
EXPOSE ${PORT}
# Model is expected to be mounted at /model at runtime.# Example: docker run -v /path/to/base_model_qwen7b:/model:ro stack-2.9-gpuENV MODEL_PATH=/model
ENTRYPOINT ["python", "inference_api.py"]12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879name: stack-2.9
python_env: python_env.yaml
entry_points: main: command: "python train.py --train_data data/final/train.jsonl --val_data data/final/val.jsonl"
evaluate: command: "python evaluate_model.py --model models/checkpoint --eval_data data/final/test.jsonl"
augment: command: "python scripts/augment_training_data.py --input training-data/tool_examples.jsonl --output training-data/augmented.jsonl --multiplier 3"
validate: command: "python scripts/validate_training_data.py --input training-data/tool_examples.jsonl"
parameters: - name: train_data default: data/final/train.jsonl - name: val_data default: data/final/val.jsonl - name: model_name default: Qwen/Qwen2.5-7B - name: batch_size default: 4 type: int - name: learning_rate default: 5.0e-5 type: float - name: num_epochs default: 3 type: int - name: warmup_steps default: 100 type: int - name: max_seq_length default: 8192 type: int - name: gradient_accumulation_steps default: 4 type: int - name: lora_rank default: 16 type: int - name: lora_alpha default: 32 type: int - name: lora_dropout default: 0.05 type: float - name: use_flash_attention default: true type: bool
run_options: # Storage for MLflow tracking tracking_uri: ./mlruns # Experiment configuration experiment: name: stack-2.9-training description: "Stack 2.9 model training experiments" # Resource limits resources: gpu_count: 1 gpu_type: A100 # Logging configuration log_model: artifacts: true save_steps: 500 # Early stopping early_stopping: metric: eval_loss patience: 2 min_delta: 0.001123475 unmodified lines80818283848586878889.PHONY: help install test train deploy cleanhelp: ## Show this help message@echo "Stack 2.9 - Makefile Commands"75 unmodified linespytest -xvs 2>/dev/null || echo "No pytest tests found"cd stack-2.9-voice && python -m pytest test_integration.py 2>/dev/null || truelint: ## Run linters@echo "🔍 Running linters..."eslint src/ 2>/dev/null || trueflake8 . 2>/dev/null || trueclean: ## Clean build artifacts@echo "🧹 Cleaning..."123475 unmodified lines8081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117.PHONY: help install test train deploy clean lint format check check-types lint-cihelp: ## Show this help message@echo "Stack 2.9 - Makefile Commands"75 unmodified linespytest -xvs 2>/dev/null || echo "No pytest tests found"cd stack-2.9-voice && python -m pytest test_integration.py 2>/dev/null || truelint: ## Run ruff linter@echo "🔍 Running ruff linter..."ruff check .@echo "✅ Lint complete"format: ## Run black formatter@echo "🎨 Running black formatter..."black .@echo "✅ Format complete"check: ## Run all quality checks@echo "🔍 Running all checks (lint + format check + type check)..."@echo ""@echo "--- Lint (ruff) ---"ruff check . || true@echo ""@echo "--- Format check (black) ---"black --check . || true@echo ""@echo "--- Type check (mypy) ---"bash scripts/check_types.sh@echo ""@echo "✅ All checks complete"check-types: ## Run mypy type checks@echo "🔍 Running mypy type checks..."bash scripts/check_types.sh@echo "✅ Type check complete"lint-ci: ## Run linters (CI-friendly, fail on errors)@echo "🔍 Running linters (CI mode)..."ruff check . --exit-non-zero-on-errorclean: ## Clean build artifacts@echo "🧹 Cleaning..."
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110# =============================================================================# Docker Compose — Stack 2.9 GPU Deployment# =============================================================================# Usage:# Start: docker compose -f docker-compose.gpu.yml up --build -d# Logs: docker compose -f docker-compose.gpu.yml logs -f# Stop: docker compose -f docker-compose.gpu.yml down# Restart: docker compose -f docker-compose.gpu.yml restart## Prerequisites:# 1. NVIDIA Container Toolkit installed:# https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html# 2. docker run --gpus all working on the host# 3. Model files present at ./base_model_qwen7b (or path set below)# =============================================================================
services: stack-2.9: build: context: . dockerfile: Dockerfile.gpu target: runtime args: UID: ${UID:-1000} GID: ${GID:-1000}
image: stack-2.9-gpu:latest container_name: stack-2.9-api
# --------------------------------------------------------------------- # GPU access — requires nvidia-container-toolkit on the host. # --------------------------------------------------------------------- deploy: resources: reservations: devices: - driver: nvidia count: all # "1" for a specific GPU capabilities: [gpu]
# --------------------------------------------------------------------- # Environment # --------------------------------------------------------------------- environment: - MODEL_PATH=/model - DEVICE=cuda - PORT=8000 - HOST=0.0.0.0 - CUDA_VISIBLE_DEVICES=0 - PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512 - TRANSFORMERS_CACHE=/model/.cache - HF_HOME=/model/.cache # Optional tuning — increase if you have ample GPU VRAM - DEFAULT_MAX_TOKENS=512 - DEFAULT_TEMPERATURE=0.2 - DEFAULT_TOP_P=0.95
# --------------------------------------------------------------------- # Port mapping — REST API # --------------------------------------------------------------------- ports: - "${STACK_PORT:-8000}:8000"
# --------------------------------------------------------------------- # Volume mounts # --------------------------------------------------------------------- volumes: # ── Model weights (read-only, essential) ────────────────────────── # Mount your fine-tuned or base Qwen-7b model directory here. # Example: ./base_model_qwen7b → /model - ${MODEL_PATH:-./base_model_qwen7b}:/model:ro
# ── HuggingFace cache (optional, speeds up rebuilds) ────────────── # Uncomment if you want to persist the HF hub cache: # - ./hf_cache:/model/.cache
# ── Inference data / logs (optional) ─────────────────────────────── # Mount a directory for additional prompt templates or static files: # - ./data:/data:ro
# --------------------------------------------------------------------- # Restart policy # --------------------------------------------------------------------- restart: unless-stopped
# --------------------------------------------------------------------- # Healthcheck (also defined in Dockerfile; repeated here for compose) # --------------------------------------------------------------------- healthcheck: test: ["CMD", "curl", "-sf", "http://localhost:8000/health"] interval: 30s timeout: 10s retries: 3 start_period: 120s # Model loading can take 60–90 seconds
# --------------------------------------------------------------------- # Resource limits (tune to your GPU VRAM) # --------------------------------------------------------------------- # Uncomment and adjust if you want to cap resource usage: # mem_limit: 16g # shm_size: 4g
# --------------------------------------------------------------------- # Logging # --------------------------------------------------------------------- logging: driver: json-file options: max-size: 50m max-file: "3"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174# Stack 2.9 Training Data Format
This document describes the format and structure of training data for Stack 2.9.
## Overview
Training data is stored in JSONL format (JSON Lines), where each line is a valid JSON object representing a single training example.
## File Structure
```training-data/├── tool_examples.jsonl # Original examples (1000)├── augmented_tool_examples.jsonl # Augmented examples (2-5x)└── scaled/ # Processed datasets ├── train.jsonl └── val.jsonl```
## Example Format
```json{ "messages": [ { "role": "system", "content": "You are a helpful AI assistant that can use tools to help users solve problems." }, { "role": "user", "content": "Can you show me the tests/test_main.py file?" }, { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_$1180", "type": "function", "function": { "name": "FileRead", "arguments": "{\"path\": \"src/main.py\"}" } } ] }, { "role": "tool", "content": "Successfully read file: README.md\n```markdown\n# My Project\n\nA sample project for Stack 2.9.\n```", "tool_call_id": "call_$1180", "name": "FileRead" }, { "role": "assistant", "content": "Here's the README.md:\n\n```markdown\n# My Project\n\nA sample project for Stack 2.9.\n```" } ], "tools": [ { "type": "function", "function": { "name": "Bash", "description": "Execute bash commands in the terminal.", "parameters": { "type": "object", "properties": { "command": {"type": "string", "description": "The bash command to execute"}, "timeout": {"type": "integer", "description": "Timeout in seconds"} }, "required": ["command"] } } }, { "type": "function", "function": { "name": "FileRead", "description": "Read the contents of a file.", "parameters": { "type": "object", "properties": { "path": {"type": "string", "description": "Path to the file to read"}, "offset": {"type": "integer", "description": "Line number to start from"}, "limit": {"type": "integer", "description": "Max lines to read"} }, "required": ["path"] } } } ]}```
## Field Definitions
### Top-Level Fields
| Field | Type | Required | Description ||-------|------|----------|-------------|| `messages` | array | Yes | Array of message objects || `tools` | array | Yes | Available tools/functions || `source` | string | No | Data source identifier |
### Message Object
| Field | Type | Required | Description ||-------|------|----------|-------------|| `role` | string | Yes | One of: system, user, assistant, tool || `content` | string | Yes* | Message content (null if tool_calls present) || `tool_calls` | array | No* | Tool call requests || `tool_call_id` | string | No* | ID linking to tool response || `name` | string | No* | Tool name (for tool messages) |
*Content is required unless `tool_calls` is present. `tool_call_id` and `name` required for role="tool".
### Tool Call Object
| Field | Type | Required | Description ||-------|------|----------|-------------|| `id` | string | Yes | Unique call identifier || `type` | string | Yes | Always "function" || `function` | object | Yes | Function name and arguments || `function.name` | string | Yes | Tool/function name || `function.arguments` | object/string | Yes | JSON arguments |
## Data Sources
- **random_synthetic**: Auto-generated with random parameters- **synthetic_template**: Template-based synthetic examples- **augmented_***: Augmented from other sources- **original**: Human-curated examples
## Augmentation
The augmentation script applies these transformations:
1. **Paraphrasing**: Reword user prompts (70% chance)2. **Difficulty scaling**: Add complexity modifiers3. **Parameter variation**: Change file paths, commands4. **Filler words**: Add "please", "thanks" (30% chance)5. **Edge cases**: Empty input, multi-step, error handling
Run augmentation:```bashpython scripts/augment_training_data.py \ --input training-data/tool_examples.jsonl \ --output training-data/augmented.jsonl \ --multiplier 3```
## Validation
Run validation to check data quality:```bashpython scripts/validate_training_data.py --input training-data/tool_examples.jsonl```
Checks include:- Required fields present- Valid JSON syntax- Message role ordering- Tool call structure- No empty entries
## Converting to Training Format
For training, convert to standard format:```python# Example conversionpython scripts/combine_datasets.py \ --input training-data/augmented.jsonl \ --output data/final/train.jsonl \ --format chatml```12 unmodified lines1314151617181981 unmodified lines10110210310410510610712 unmodified linesimport jsonimport timeimport tracebackfrom typing import List, Dict, Tuple, Optionalfrom collections import defaultdictimport itertoolsimport torch81 unmodified linesreturn completion.strip()def execute_code(code: str, timeout: int = 5) -> Tuple[bool, str, Optional[any]]:"""Safely execute code and return (success, error_msg, result).Uses restricted builtins and timeout for safety.12 unmodified lines1314151617181981 unmodified lines10110210310410510610712 unmodified linesimport jsonimport timeimport tracebackfrom typing import Any, Dict, List, Optional, Tuplefrom collections import defaultdictimport itertoolsimport torch81 unmodified linesreturn completion.strip()def execute_code(code: str, timeout: int = 5) -> Tuple[bool, str, Optional[Any]]:"""Safely execute code and return (success, error_msg, result).Uses restricted builtins and timeout for safety.
2 unmodified lines34567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677782 unmodified linesbuild-backend = "setuptools.build_meta"[project]name = "devpilot"version = "0.1.0"description = "AI-powered voice cloning and synthesis platform"readme = "README.md"license = {text = "MIT"}authors = [{name = "Walid Sobhi", email = "walid@example.com"}]keywords = ["voice", "cloning", "tts", "speech-synthesis", "ai", "audio"]classifiers = ["Development Status :: 3 - Alpha","Intended Audience :: Developers","License :: OSI Approved :: MIT License","Programming Language :: Python :: 3","Programming Language :: Python :: 3.8","Programming Language :: Python :: 3.9","Programming Language :: Python :: 3.10","Programming Language :: Python :: 3.11","Topic :: Multimedia :: Sound/Audio :: Speech",]requires-python = ">=3.8"dependencies = ["coqui-tts>=0.20.0","librosa>=0.10.0","soundfile>=0.12.0","numpy>=1.24.0","torch>=2.0.0","tqdm>=4.65.0","pydantic>=2.0.0",][project.optional-dependencies]dev = ["pytest>=7.0.0","pytest-cov>=4.0.0","flake8>=6.0.0","black>=23.0.0","mypy>=1.0.0",]web = ["gradio>=3.50.0",][project.scripts]devpilot = "devpilot.cli:main"devpilot-web = "devpilot.web:main"[project.urls]Homepage = "https://github.com/my-ai-stack/devpilot"Documentation = "https://github.com/my-ai-stack/devpilot#readme"Repository = "https://github.com/my-ai-stack/devpilot"Issues = "https://github.com/my-ai-stack/devpilot/issues"Changelog = "https://github.com/my-ai-stack/devpilot/releases"[tool.setuptools.packages.find]where = ["."]include = ["devpilot*"][tool.black]line-length = 100target-version = ['py38', 'py39', 'py310', 'py311']include = '\.pyi?$'[tool.pytest.ini_options]testpaths = ["tests"]python_files = ["test_*.py", "*_test.py"]addopts = "-v --cov=devpilot --cov-report=term-missing"[tool.mypy]python_version = "3.8"warn_return_any = truewarn_unused_configs = truedisallow_untyped_defs = false2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383940414243444546474849502 unmodified linesbuild-backend = "setuptools.build_meta"[project]name = "stack-2.9"version = "0.1.0"description = "AI coding assistant with pattern memory and tool calling"readme = "README.md"license = {text = "MIT"}requires-python = ">=3.10"dependencies = ["transformers>=4.40.0","peft>=0.10.0","accelerate>=0.34.0","datasets>=3.0.0","torch>=2.2.0","pyyaml>=6.0","fastapi>=0.115.0","uvicorn[standard]>=0.30.0","pydantic>=2.0.0",][project.optional-dependencies]dev = ["ruff>=0.8.0","black>=24.0.0","mypy>=1.0.0","pytest>=8.0.0",][tool.ruff]line-length = 100target-version = "py310"[tool.ruff.lint]select = ["E", "F", "I", "N", "W", "UP", "B"]ignore = ["E501"][tool.black]line-length = 100target-version = ["py310"][tool.mypy]python_version = "3.10"warn_return_any = truewarn_unused_ignores = true[tool.pytest.ini_options]testpaths = ["tests"]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324#!/usr/bin/env python3"""Data augmentation script for tool_examples.jsonl.Generates 2x-5x more training examples from existing data through:- Paraphrasing user prompts- Difficulty scaling (simpler/complex variations)- Edge case generation"""
import jsonimport randomimport argparsefrom pathlib import Pathfrom typing import List, Dict, Any, Optionalfrom itertools import productimport copy
# Random seed for reproducibilityrandom.seed(42)
# Paraphrase templatesPARAPHRASES = { "Can you": ["Please", "Would you kindly", "Could you", "Kindly"], "I need": ["I'd like", "I require", "I want", "I must have"], "show me": ["display", "show", "reveal", "let me see"], "the file": ["this file", "that file", "a file"], "run": ["execute", "launch", "start", "run"], "create": ["make", "generate", "add", "write"], "delete": ["remove", "erase", "drop", "destroy"], "list": ["show", "display", "enumerate", "get"], "search": ["find", "look for", "grep", "locate"], "help me": ["assist me", "I need help", "please assist", "support"],}
# Difficulty modifiersEASY_MODIFIERS = [ "quickly", "simply", "just", "easily",]
COMPLEX_MODIFIERS = [ "carefully", "thoroughly", "in detail", "completely", "with all options",]
# Edge case patternsEDGE_CASE_PATTERNS = [ ("empty_input", lambda ex: _create_empty_variant(ex)), ("multi_step", lambda ex: _create_multistep_variant(ex)), ("error_handling", lambda ex: _create_error_variant(ex)),]
def _deep_copy(obj: Any) -> Any: """Create a deep copy of a JSON-serializable object.""" return json.loads(json.dumps(obj))
def _create_empty_variant(example: Dict[str, Any]) -> Optional[Dict[str, Any]]: """Create variant with empty/blank user input.""" new_ex = _deep_copy(example) # Keep system message, empty user message for msg in new_ex["messages"]: if msg["role"] == "user": msg["content"] = " " break new_ex["source"] = "augmented_edge_empty" return new_ex
def _create_multistep_variant(example: Dict[str, Any]) -> Optional[Dict[str, Any]]: """Create variant simulating multi-step reasoning.""" new_ex = _deep_copy(example) # Add reasoning step before tool call for i, msg in enumerate(new_ex["messages"]): if msg.get("tool_calls"): reasoning = { "role": "assistant", "content": "Let me think about this step by step. First, I need to understand what the user is asking for." } new_ex["messages"].insert(i, reasoning) break new_ex["source"] = "augmented_edge_multistep" return new_ex
def _create_error_variant(example: Dict[str, Any]) -> Optional[Dict[str, Any]]: """Create variant simulating error handling.""" new_ex = _deep_copy(example) for msg in new_ex["messages"]: if msg.get("role") == "tool": # Simulate an error in tool result if "Successfully" in msg.get("content", ""): msg["content"] = msg["content"].replace("Successfully", "Error occurred:") elif "error" not in msg.get("content", "").lower(): msg["content"] = "Operation failed: Permission denied" break new_ex["source"] = "augmented_edge_error" return new_ex
def paraphrase_text(text: str) -> str: """Apply simple paraphrasing to text.""" if not text: return text result = text for original, alternatives in PARAPHRASES.items(): if original.lower() in result.lower(): # Case-insensitive replace, preserve original case pattern idx = result.lower().find(original.lower()) prefix = result[:idx] suffix = result[idx + len(original):] replacement = random.choice(alternatives) # Preserve case if result[idx].isupper(): replacement = replacement.capitalize() result = prefix + replacement + suffix break return result
def apply_difficulty(example: Dict[str, Any], level: str) -> Dict[str, Any]: """Apply difficulty scaling to an example.""" new_ex = _deep_copy(example) modifiers = EASY_MODIFIERS if level == "easy" else COMPLEX_MODIFIERS for msg in new_ex["messages"]: if msg["role"] == "user" and msg.get("content"): content = msg["content"] if level == "easy": # Simplify the request content = content.replace("please", "").replace("kindly", "") content = content.strip() elif level == "complex": # Add complexity modifier = random.choice(modifiers) content = f"{content} {modifier}" msg["content"] = content break new_ex["source"] = f"augmented_difficulty_{level}" return new_ex
def vary_tool_parameters(example: Dict[str, Any]) -> List[Dict[str, Any]]: """Generate variations with different tool parameters.""" variations = [] for msg in example.get("messages", []): if msg.get("tool_calls"): for tc in msg["tool_calls"]: func = tc.get("function", {}) args_str = func.get("arguments", "{}") try: args = json.loads(args_str) if isinstance(args_str, str) else args_str except (json.JSONDecodeError, TypeError): continue if not isinstance(args, dict): continue # Common parameter variations param_variations = [ ("file_path", ["src/main.py", "README.md", "config.yaml", "package.json", "tests/test.py"]), ("command", ["ls -la", "echo hello", "pwd", "whoami"]), ("pattern", ["*.py", "*.js", "*.md", "*.json"]), ("path", ["src", "lib", "docs", "."]), ] for param_name, alternatives in param_variations: if param_name in args: original_val = args[param_name] for alt_val in alternatives: if alt_val != original_val: new_ex = _deep_copy(example) for new_msg in new_ex["messages"]: if new_msg.get("tool_calls"): for new_tc in new_msg["tool_calls"]: new_func = new_tc.get("function", {}) new_args = json.loads(new_func.get("arguments", "{}")) if param_name in new_args: new_args[param_name] = alt_val new_func["arguments"] = json.dumps(new_args) new_ex["source"] = "augmented_params" variations.append(new_ex) break return variations
def add_filler_variant(example: Dict[str, Any]) -> Optional[Dict[str, Any]]: """Add polite filler words to user message.""" fillers = [" please", " if you could", " when you get a chance", " thanks"] new_ex = _deep_copy(example) for msg in new_ex["messages"]: if msg["role"] == "user" and msg.get("content"): filler = random.choice(fillers) msg["content"] = msg["content"].rstrip() + filler break new_ex["source"] = "augmented_filler" return new_ex
def generate_edge_cases(example: Dict[str, Any], num_cases: int = 2) -> List[Dict[str, Any]]: """Generate edge case variations.""" cases = [] selected_patterns = random.sample(EDGE_CASE_PATTERNS, min(num_cases, len(EDGE_CASE_PATTERNS))) for name, generator in selected_patterns: try: variant = generator(example) if variant: cases.append(variant) except Exception: continue return cases
def augment_example(example: Dict[str, Any], target_multiplier: int = 3) -> List[Dict[str, Any]]: """Generate multiple augmented variations of a single example.""" variations = [example] # Always keep original # 1. Paraphrase variant if random.random() < 0.7: new_ex = _deep_copy(example) for msg in new_ex["messages"]: if msg["role"] == "user" and msg.get("content"): msg["content"] = paraphrase_text(msg["content"]) break new_ex["source"] = "augmented_paraphrase" variations.append(new_ex) # 2. Difficulty variants (easy and complex) if random.random() < 0.5: variations.append(apply_difficulty(example, "easy")) if random.random() < 0.5: variations.append(apply_difficulty(example, "complex")) # 3. Filler variant if random.random() < 0.3: filler_ex = add_filler_variant(example) if filler_ex: variations.append(filler_ex) # 4. Tool parameter variations param_variations = vary_tool_parameters(example) variations.extend(param_variations[:2]) # Limit to 2 # 5. Edge cases if random.random() < 0.3: edge_cases = generate_edge_cases(example) variations.extend(edge_cases[:1]) return variations[:target_multiplier] # Limit total variations
def main(): parser = argparse.ArgumentParser(description="Augment training data for Stack 2.9") parser.add_argument("--input", type=str, default="training-data/tool_examples.jsonl", help="Input JSONL file") parser.add_argument("--output", type=str, default="training-data/augmented_tool_examples.jsonl", help="Output JSONL file") parser.add_argument("--multiplier", type=int, default=3, help="Target multiplication factor (2-5)") parser.add_argument("--seed", type=int, default=42, help="Random seed for reproducibility") args = parser.parse_args() random.seed(args.seed) input_path = Path(args.input) output_path = Path(args.output) if not input_path.exists(): print(f"Error: Input file not found: {input_path}") return print(f"Loading data from: {input_path}") examples = [] with open(input_path, 'r', encoding='utf-8') as f: for line in f: line = line.strip() if line: try: examples.append(json.loads(line)) except json.JSONDecodeError: continue original_count = len(examples) print(f"Loaded {original_count} examples") # Generate augmented examples all_variations = [] for ex in examples: variations = augment_example(ex, target_multiplier=args.multiplier) all_variations.extend(variations) total_count = len(all_variations) # Write output output_path.parent.mkdir(parents=True, exist_ok=True) with open(output_path, 'w', encoding='utf-8') as f: for var in all_variations: f.write(json.dumps(var, ensure_ascii=False) + "\n") print(f"\nAugmentation complete!") print(f" Original: {original_count} examples") print(f" Augmented: {total_count} examples") print(f" Multiplier: {total_count/original_count:.1f}x") print(f" Output: {output_path}")
if __name__ == "__main__": main()12345678910111213141516171819202122232425262728293031#!/usr/bin/env bash# Run mypy type checking on the codebaseset -e
echo "🔍 Running mypy type checks..."
# Run mypy on key Python filesmypy \ --python-version 3.8 \ --warn-return-any \ --warn-unused-configs \ --ignore-missing-imports \ --strict-optional \ --warn-redundant-casts \ --warn-unused-ignores \ --show-error-codes \ --show-column-numbers \ test_model.py \ evaluate_model.py \ inference_api.py \ merge_simple.py \ train_local.py \ train_simple_nobnb.py \ src/ \ stack/ \ || { echo "❌ mypy found type errors" exit 1 }
echo "✅ mypy type check passed"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352#!/usr/bin/env python3"""Validate JSONL training data quality.Checks:- Required fields present- tool_calls format valid- No empty/invalid entries"""
import jsonimport argparsefrom pathlib import Pathfrom typing import Dict, List, Any, Tuple, Optionalfrom collections import Counter
# Required top-level fieldsREQUIRED_FIELDS = ["messages", "tools"]
# Required message fieldsREQUIRED_MSG_FIELDS = ["role", "content"]
# Valid rolesVALID_ROLES = {"system", "user", "assistant", "tool"}
# Required message structure for tool conversationsMUST_HAVE_ROLES = ["user", "assistant"]
class ValidationError: def __init__(self, line_num: int, field: str, message: str, severity: str = "error"): self.line_num = line_num self.field = field self.message = message self.severity = severity # error, warning, info def __repr__(self): return f"[{self.severity.upper()}] Line {self.line_num}: {self.field} - {self.message}"
class DataValidator: def __init__(self, strict: bool = False): self.errors: List[ValidationError] = [] self.warnings: List[ValidationError] = [] self.stats = { "total_lines": 0, "valid_lines": 0, "lines_with_tools": 0, "tool_names": Counter(), "message_roles": Counter(), } self.strict = strict def validate_field_exists(self, data: Dict, field: str, line_num: int) -> bool: """Check if a required field exists.""" if field not in data: self.errors.append(ValidationError( line_num, field, f"Missing required field: '{field}'" )) return False return True def validate_message_structure(self, msg: Dict, line_num: int, msg_idx: int) -> bool: """Validate a single message structure.""" valid = True # Check required fields for field in REQUIRED_MSG_FIELDS: if field not in msg: self.errors.append(ValidationError( line_num, f"messages[{msg_idx}]", f"Missing required field: '{field}'" )) valid = False # Validate role role = msg.get("role") if role and role not in VALID_ROLES: self.errors.append(ValidationError( line_num, f"messages[{msg_idx}].role", f"Invalid role: '{role}'. Must be one of: {VALID_ROLES}" )) valid = False # Validate tool_calls structure if msg.get("tool_calls"): valid &= self._validate_tool_calls(msg["tool_calls"], line_num, msg_idx) # Validate tool result structure if role == "tool": if "tool_call_id" not in msg and "tool_call_id" not in str(msg): self.warnings.append(ValidationError( line_num, f"messages[{msg_idx}]", "Tool message missing tool_call_id", severity="warning" )) return valid def _validate_tool_calls(self, tool_calls: Any, line_num: int, msg_idx: int) -> bool: """Validate tool_calls structure.""" if not isinstance(tool_calls, list): self.errors.append(ValidationError( line_num, f"messages[{msg_idx}].tool_calls", f"tool_calls must be a list, got {type(tool_calls).__name__}" )) return False valid = True for tc_idx, tc in enumerate(tool_calls): if not isinstance(tc, dict): self.errors.append(ValidationError( line_num, f"messages[{msg_idx}].tool_calls[{tc_idx}]", f"tool_call must be an object, got {type(tc).__name__}" )) valid = False continue # Check required tool_call fields if "function" not in tc: self.errors.append(ValidationError( line_num, f"messages[{msg_idx}].tool_calls[{tc_idx}]", "Missing 'function' field in tool_call" )) valid = False continue func = tc.get("function", {}) if not isinstance(func, dict): self.errors.append(ValidationError( line_num, f"messages[{msg_idx}].tool_calls[{tc_idx}].function", f"function must be an object, got {type(func).__name__}" )) valid = False continue # Validate function.name if "name" not in func: self.errors.append(ValidationError( line_num, f"messages[{msg_idx}].tool_calls[{tc_idx}].function", "Missing 'name' field in function" )) valid = False # Validate function.arguments if "arguments" in func: args = func["arguments"] if isinstance(args, str): try: json.loads(args) except json.JSONDecodeError as e: self.errors.append(ValidationError( line_num, f"messages[{msg_idx}].tool_calls[{tc_idx}].function.arguments", f"Invalid JSON: {e}" )) valid = False elif not isinstance(args, (dict, list)): self.errors.append(ValidationError( line_num, f"messages[{msg_idx}].tool_calls[{tc_idx}].function.arguments", f"arguments must be JSON string or object, got {type(args).__name__}" )) valid = False return valid def validate_example(self, data: Dict, line_num: int) -> bool: """Validate a single training example.""" valid = True # Check required fields for field in REQUIRED_FIELDS: if not self.validate_field_exists(data, field, line_num): valid = False if not valid and self.strict: return False # Validate messages array messages = data.get("messages", []) if not isinstance(messages, list): self.errors.append(ValidationError( line_num, "messages", f"messages must be an array, got {type(messages).__name__}" )) return False if len(messages) == 0: self.errors.append(ValidationError( line_num, "messages", "messages array is empty" )) valid = False # Validate each message has_user = False has_assistant = False for idx, msg in enumerate(messages): if self.validate_message_structure(msg, line_num, idx): role = msg.get("role") self.stats["message_roles"][role] += 1 if role == "user": has_user = True elif role == "assistant": has_assistant = True # Warn if missing essential roles if not has_user: self.warnings.append(ValidationError( line_num, "messages", "No user message found", severity="warning" )) if not has_assistant: self.warnings.append(ValidationError( line_num, "messages", "No assistant message found", severity="warning" )) # Extract tool names for stats for msg in messages: if msg.get("tool_calls"): self.stats["lines_with_tools"] += 1 for tc in msg["tool_calls"]: func = tc.get("function", {}) name = func.get("name", "unknown") self.stats["tool_names"][name] += 1 break return valid def validate_file(self, filepath: Path) -> Tuple[int, int]: """Validate an entire JSONL file.""" print(f"Validating: {filepath}") print("-" * 50) with open(filepath, 'r', encoding='utf-8') as f: for line_num, line in enumerate(f, start=1): line = line.strip() if not line: continue self.stats["total_lines"] += 1 try: data = json.loads(line) except json.JSONDecodeError as e: self.errors.append(ValidationError( line_num, "JSON", f"Invalid JSON: {e}" )) continue if self.validate_example(data, line_num): self.stats["valid_lines"] += 1 return len(self.errors), len(self.warnings) def print_report(self): """Print validation report.""" print("\n" + "=" * 50) print("VALIDATION REPORT") print("=" * 50) print(f"\n📊 Statistics:") print(f" Total lines: {self.stats['total_lines']}") print(f" Valid lines: {self.stats['valid_lines']}") print(f" Valid率: {self.stats['valid_lines']/max(1,self.stats['total_lines'])*100:.1f}%") print(f" Lines with tools: {self.stats['lines_with_tools']}") if self.stats["tool_names"]: print(f"\n🔧 Top tool names:") for name, count in self.stats["tool_names"].most_common(10): print(f" - {name}: {count}") if self.stats["message_roles"]: print(f"\n💬 Message roles:") for role, count in self.stats["message_roles"].most_common(): print(f" - {role}: {count}") if self.errors: print(f"\n❌ Errors ({len(self.errors)}):") for err in self.errors[:20]: # Show first 20 print(f" {err}") if len(self.errors) > 20: print(f" ... and {len(self.errors) - 20} more") if self.warnings: print(f"\n⚠️ Warnings ({len(self.warnings)}):") for warn in self.warnings[:10]: # Show first 10 print(f" {warn}") if len(self.warnings) > 10: print(f" ... and {len(self.warnings) - 10} more") if not self.errors and not self.warnings: print("\n✅ All checks passed!") return len(self.errors) == 0
def main(): parser = argparse.ArgumentParser(description="Validate training data JSONL files") parser.add_argument("files", nargs="*", help="JSONL files to validate (default: training-data/*.jsonl)") parser.add_argument("--input", type=str, default="training-data/tool_examples.jsonl", help="Input JSONL file") parser.add_argument("--strict", action="store_true", help="Fail on any missing required field") parser.add_argument("--ignore-warnings", action="store_true", help="Only show errors, not warnings") args = parser.parse_args() # Determine files to validate files = [] if args.files: files = [Path(f) for f in args.files] else: input_path = Path(args.input) if input_path.exists(): files = [input_path] else: # Try glob pattern data_dir = input_path.parent files = list(data_dir.glob("*.jsonl")) if not files: print("Error: No files to validate") return 1 all_passed = True for filepath in files: validator = DataValidator(strict=args.strict) error_count, warn_count = validator.validate_file(filepath) if not args.ignore_warnings: passed = validator.print_report() else: passed = error_count == 0 if error_count > 0: print(f"\n❌ {filepath}: {error_count} errors found") if not passed: all_passed = False print() return 0 if all_passed else 1
if __name__ == "__main__": exit(main())10 unmodified lines1112131415161773 unmodified lines9192939495969710 unmodified linesimport argparseimport jsonimport timefrom typing import List, Dict, Tuple, Optionalimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizer73 unmodified linesreturn completion.strip()def execute_code(code: str, timeout: int = 5) -> Tuple[bool, str, Optional[any]]:"""Safely execute code and return (success, error_msg, result)."""import signal10 unmodified lines1112131415161773 unmodified lines9192939495969710 unmodified linesimport argparseimport jsonimport timefrom typing import Any, Dict, List, Optional, Tupleimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizer73 unmodified linesreturn completion.strip()def execute_code(code: str, timeout: int = 5) -> Tuple[bool, str, Optional[Any]]:"""Safely execute code and return (success, error_msg, result)."""import signal