b4rty/torchdebug-env
๐ฅ TorchDebug โ PyTorch Training Run Debugger
An OpenEnv environment that challenges AI agents to diagnose and fix real-world PyTorch training failures.
  
๐ฏ What is TorchDebug?
TorchDebug simulates the real work of an ML engineer debugging broken training runs. A training run is presented with:
- ๐ Training logs showing loss/accuracy/gradient progression
- ๐ป Code snippets containing one or more bugs
- โ๏ธ Configuration detailing hyperparameters and setup
- โ Error messages (if the run crashed)
The agent must investigate (analyze logs, inspect gradients, check architecture), diagnose the root cause, and prescribe a fix. Performance is graded on diagnosis accuracy, fix quality, investigation efficiency, and hint usage.
๐๏ธ Architecture
Reference-inspired layout (aligned with strong OpenEnv environments such as calendar/reasoning_gym/repl/tbench2):
torchdebug_env/
โโโ ARCHITECTURE.md # Design and layering notes
โโโ openenv.yaml # OpenEnv manifest
โโโ pyproject.toml # Dependencies
โโโ models.py # Pydantic Action/Observation/State models
โโโ client.py # Typed EnvClient wrapper
โโโ inference.py # Baseline LLM agent script
โโโ __init__.py
โโโ server/
โ โโโ app.py # FastAPI server entry point
โ โโโ torchdebug_environment.py # Core Environment implementation
โ โโโ Dockerfile # Container build
โโโ scenarios/
โ โโโ __init__.py # Scenario registry
โ โโโ basic_failures.py # Task 1: Easy scenarios
โ โโโ performance_issues.py # Task 2: Medium scenarios
โ โโโ subtle_bugs.py # Task 3: Hard scenarios
โโโ utils/
โโโ reward.py # Grading & reward computation๐ Tasks & Scenarios
Task 1: Basic Failures (Easy) โ 5 Scenarios
Task 2: Performance Issues (Medium) โ 5 Scenarios
Task 3: Subtle & Compound Bugs (Hard) โ 5 Scenarios
๐ค Agent Interface
Available Actions
Reward Structure
๐ Quick Start
1. Start the Environment Server
# Install dependencies
pip install -e .
# Run locally
uvicorn server.app:app --host 0.0.0.0 --port 8000
# Or with Docker
docker build -f server/Dockerfile -t torchdebug-env .
docker run -p 8000:8000 torchdebug-env2. Run Baseline Inference
# Required variables
export API_BASE_URL="https://api.openai.com/v1"
export MODEL_NAME="gpt-4"
export HF_TOKEN="sk-..."
python inference.py
# With HuggingFace Inference
export API_BASE_URL="https://api-inference.huggingface.co/v1"
export MODEL_NAME="meta-llama/Llama-3.3-70B-Instruct"
export HF_TOKEN="hf_..."
python inference.pyThe baseline evaluates one deterministic scenario from each task (easy/medium/hard) and writes reproducible scores to outputs/evals/baseline_results.json.
3. Validate
openenv validate torchdebug_env4. Run Pre-submission Checks (Recommended)
# Core checks (validate + local reset/step smoke tests)
python presubmit.py
# Core + deterministic grader tests are run by default
# Use --skip-tests only if your environment cannot run pytest
python presubmit.py --skip-tests
# Include container checks (docker build/run + /health + /reset)
python presubmit.py --docker
# Include baseline run (requires API_BASE_URL, MODEL_NAME, HF_TOKEN)
python presubmit.py --docker --baselineFor HF Space style external validation, use scripts/validate-submission.sh.
presubmit.py now also writes a machine-readable report to outputs/evals/submission_report.json.
๐ Baseline Results
๐ง Development
# Clone and install
git clone <repo-url>
cd torchdebug_env
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Build Docker
openenv build torchdebug_env๐ HuggingFace Space Deployment
# Deploy to HuggingFace Spaces
openenv deploy torchdebug_env --space your-username/torchdebug-env๐ License
BSD-3-Clause โ Compatible with Meta/PyTorch licensing.
๐ Hackathon Context
Built for the Meta PyTorch OpenEnv Hackathon ร Scaler School (Round 1).
Why TorchDebug matters:
- ๐ฅ Real-world utility: Every ML engineer spends hours debugging training runs
- ๐ฏ Sponsor alignment: Showcases PyTorch ecosystem deeply (DDP, FSDP, AMP, transformers)
- ๐ง Progressive difficulty: Tests both basic knowledge and advanced distributed training skills
- ๐ Meaningful rewards: Partial credit for investigation โ not just binary pass/fail
๐งช Judging Criteria Mapping (Round 1)
1) Real-world utility (30%)
- Environment models a real ML engineering workflow: diagnosing failed/underperforming PyTorch training jobs.
- Scenarios include production-like issues: device mismatch, data leakage, AMP instability, DDP/FSDP interactions.
2) Task & grader quality (25%)
- 3 difficulty tiers (easy โ medium โ hard) with deterministic scenario definitions.
- Programmatic scoring in utils/reward.py returns bounded scores in $[0,1]$.
- Grader includes anti-gaming logic and evidence-alignment incentives.
3) Environment design (20%)
- Clean episode lifecycle via
reset()/step()/state()patterns. - Typed action/observation/state models in models.py.
- Reward shaping includes partial progress, efficiency terms, and hint penalties.
4) Code quality & OpenEnv compliance (15%)
- OpenEnv manifest in openenv.yaml.
- Local validation and smoke-check automation in presubmit.py.
- External submission validator in scripts/validate-submission.sh.
- Dockerized runtime via server/Dockerfile.
5) Creativity & novelty (10%)
- Focuses on training-debug intelligence rather than benchmark gaming.
- Hard tasks require multi-factor reasoning (numerics + systems + architecture).
๐ Final Submission Tips (High Impact)
- Use a hard scenario baseline in
inference.pyoutput to demonstrate non-trivial agent capability. - Include the generated artifacts:
- outputs/evals/baseline_results.json
- outputs/evals/submission_report.json
- Before submitting HF URL, run:
python presubmit.py --docker --baselinebash scripts/validate-submission.sh https://<your-space>.hf.space .
โ Submission Checklist (Practical)
- [ ]
openenv validate .passes - [ ]
python presubmit.py --dockerpasses - [ ]
python presubmit.py --baselinepasses with valid API credentials - [ ]
outputs/evals/baseline_results.jsonis generated and committed (or attached) - [ ] Hugging Face Space is deployed and responds to
/healthand/reset
๐จ Submission Portal Inputs
Use these exact links in the hackathon submission form:
- GitHub Repository URL:
https://github.com/<your-username>/<your-repo> - Hugging Face Space URL:
https://huggingface.co/spaces/b4rty/torchdebug-env
Optional live runtime URL (for your own checks):
https://b4rty-torchdebug-env.hf.space
๐งพ Final One-Command Validation
After setting env vars (API_BASE_URL, MODEL_NAME, HF_TOKEN), run:
python presubmit.py --docker --baseline
bash scripts/validate-submission.sh https://b4rty-torchdebug-env.hf.space .This generates/updates:
- outputs/evals/submission_report.json
- outputs/evals/baseline_results.json
