OpenScience - ML Workflow Defaults
This file provides default instructions for the OpenScience when working in ML/AI research projects.
Skill Loading Guide
Load skills proactively based on the task at hand:
Training & Post-Training
- RLHF/GRPO/DPO →
grpo-rl-training,trl-fine-tuning,openrlhf,simpo - Fine-tuning →
axolotl,unsloth,llama-factory,torchtune - Distributed →
deepspeed-training,fsdp,megatron-core,accelerate
Inference & Serving
- High-throughput →
vllm-inference,sglang,tensorrt-llm - Local/Edge →
llama-cpp,gguf-quantization - Optimization →
flash-attention,gptq,awq,bitsandbytes
Evaluation & Analysis
- Benchmarking →
lm-eval-harness,bigcode-eval,nemo-evaluator - Interpretability →
transformer-lens,saelens,nnsight,pyvene
RAG & Retrieval
- Vector stores →
chroma,faiss,pinecone,qdrant - Embeddings →
sentence-transformers - Orchestration →
langchain,llamaindex
Agents & Structured Output
- Agent frameworks →
langchain,llamaindex,crewai - Structured output →
dspy,instructor,guidance,outlines
Multimodal
- Vision →
clip,llava,segment-anything,stable-diffusion - Audio →
whisper,audiocraft - Document →
blip-2
Data & Infrastructure
- Data processing →
ray-data,nemo-curator - Cloud compute →
modal,skypilot,lambda-labs - Experiment tracking →
weights-and-biases,mlflow,tensorboard
Emerging Techniques
- Scaling →
moe-training,speculative-decoding,long-context - Compression →
knowledge-distillation,model-pruning,model-merging
ML Workflow Standards
Before Training
- Check GPU availability:
nvidia-smiortorch.cuda.is_available() - Verify CUDA version compatibility with frameworks
- Estimate memory requirements for model + optimizer + gradients
- Set up experiment tracking (W&B or MLflow)
- Validate dataset format and tokenization
Training Best Practices
- Use bf16 on Ampere+ GPUs (A100, H100, RTX 30xx+), fp16 otherwise
- Enable gradient checkpointing for memory-constrained setups
- Save checkpoints every N steps (N = training_time_hours * 2)
- Log learning rate, loss, and gradient norms
- Set random seeds for reproducibility:
torch.manual_seed(42)
Memory Optimization Priority
- Gradient checkpointing (free, ~30% memory reduction)
- Mixed precision training (free, ~50% memory reduction)
- Gradient accumulation (free, enables larger effective batch)
- DeepSpeed ZeRO Stage 2 (minimal overhead)
- Model sharding / FSDP (for multi-GPU)
OOM Error Handling
When encountering CUDA OOM:
- Reduce batch size by 50%
- Enable gradient checkpointing
- Switch to 8-bit optimizer (bitsandbytes)
- Try DeepSpeed ZeRO offloading
- Consider model parallelism for very large models
Code Style Guidelines
Preferred Patterns
- Use HuggingFace Transformers for model loading
- Use
acceleratefor device management - Use
datasetslibrary for data loading - Use
peftfor parameter-efficient fine-tuning
Example Setup
import torch
from accelerate import Accelerator
from transformers import AutoModelForCausalLM, AutoTokenizer
accelerator = Accelerator(mixed_precision="bf16")
model = AutoModelForCausalLM.from_pretrained(
"model-name",
torch_dtype=torch.bfloat16,
device_map="auto",
)
Environment Variables
Key environment variables for ML workflows:
CUDA_VISIBLE_DEVICES- GPU selectionWANDB_PROJECT- W&B project nameHF_TOKEN- HuggingFace API tokenTRANSFORMERS_CACHE- Model cache directory