environment.yml: For systems with NVIDIA GPUs and CUDA support (recommended)environment_cpu.yml: For systems without GPUs or CUDA (CPU-only)
Try these solutions in order:
-
Update conda first:
conda update conda
-
Use mamba for faster solving (if available):
mamba env create -f environment.yml
-
Try the CPU environment even if you have a GPU:
conda env create -f environment_cpu.yml
-
Get a key from Google Perspective API
-
Method 1 - Edit environment file (Recommended):
- Edit
environment.ymlorenvironment_cpu.yml - Replace
"your_api_key_here"with your actual key - Recreate the environment:
conda env create -f environment.yml --force
- Edit
-
Method 2 - Set environment variable:
export PERSPECTIVE_API_KEY="your_actual_key_here"
-
Method 3 - Set in notebook:
import os os.environ['PERSPECTIVE_API_KEY'] = "your_actual_key_here"
Most common cause: Wrong conda environment
Solution:
# Check current environment
echo $CONDA_DEFAULT_ENV
# If not 'trace', activate it:
conda activate trace
# Restart Jupyter if using notebooks:
jupyter labOther causes to check:
- Missing PyTorch:
python -c "import torch; print('✅ PyTorch works')" - Missing Transformers:
python -c "import transformers; print('✅ Transformers works')" - Invalid API key: Check your Perspective API key is valid
You're running in the wrong conda environment or PyTorch isn't installed.
Solution:
conda activate trace
python -c "import torch" # Test if PyTorch is availableIf PyTorch is missing, recreate the environment:
conda env remove -n trace
conda env create -f environment.ymlInvalid key:
- Verify your key at the Perspective API console
- Make sure the API is enabled for your project
Rate limiting:
- The free tier has rate limits
- Reduce batch size:
python src/score.py --batch_size 1 - Add delays between requests (implemented automatically)
Reduce batch sizes:
python src/score.py --batch_size 1
python src/generate.py --generation_batch_size 1 --prompt_batch_size 1Use CPU-only mode:
python src/score.py --device cpuExpected behavior:
- Fluency scoring loads GPT2-XL (1.5B parameters)
- Toxicity scoring makes API calls
- ~2-3 seconds per prompt is normal
Speed up options:
- Increase batch size:
--batch_size 10(if memory allows) - Use GPU: Make sure CUDA is working
Missing HMM model:
# Download from HuggingFace Hub
pip install huggingface_hub
python -c "
from huggingface_hub import snapshot_download
snapshot_download(repo_id='gwenweng/hmm-gpt2-large', local_dir='models/hmm_gpt2-large_uncon_seq-len-32_4096_10M')
"Missing data files:
data/prompts.jsonlshould be included in the repositorydata/coefficients.csvshould be included in the repository- For full evaluation, download
RTP_test.jsonlseparately
On shared systems:
# Use --user flag for pip installs
pip install --user package_name
# Or create environment in your home directory
conda env create -f environment.yml --prefix ~/envs/trace
conda activate ~/envs/traceCheck inputs:
- Verify
data/prompts.jsonlformat:{"prompt": {"text": "your prompt here"}} - Make sure prompts aren't too long (>512 tokens)
Check parameters:
- Default
--a 1.0is usually good - Try
--a 0.5for less guidance or--a 2.0for more - Increase
--max_lenif outputs are too short
Memory issues: Reduce batch sizes
Model loading issues: Check HMM model path exists
CUDA issues: Try --device cpu
This is handled automatically by the environment files, but if you see MKL errors:
export MKL_SERVICE_FORCE_INTEL=1
export MKL_THREADING_LAYER=GNUFor generation:
python src/generate.py --model_path gpt2-medium # Use different base modelFor scoring:
python src/score.py --perp_model gpt2-large # Use different fluency modelStep 1: Score training data for your attribute:
python src/score_attribute.py --attribute politicsStep 2: Train classifier:
python src/fit.py --data_path data/RTP_train_politics.jsonl --attribute politicsStep 3: Use in generation:
python src/generate.py --weights_path data/coefficients_politics.csvCommon attributes: politics, sports, emotion, formality, sentiment, entertainment
Reproducibility:
- Set seed:
--seed 42 - Use same model versions
- Check hardware differences (GPU vs CPU can give slightly different results)
Parameter sensitivity:
- TRACE is sensitive to
--aparameter - HMM quality affects results
- Toxicity classifier affects guidance
Memory issues:
- Restart kernel and clear outputs
- Close other notebooks
- Use smaller models or batch sizes
Environment issues:
- Make sure Jupyter is running in the 'trace' environment
- Install jupyter in the environment:
conda install jupyterlab
Missing matplotlib:
conda activate trace
conda install matplotlib seabornDisplay issues:
import matplotlib
matplotlib.use('Agg') # Use non-interactive backendIf these solutions don't work:
- Check the GitHub Issues: github.com/yidouweng/trace/issues
- Create a new issue with:
- Your operating system
- Python/conda versions
- Full error message
- Steps to reproduce
- Include environment info:
conda list > environment_info.txt python --version nvidia-smi # If using GPU
- Paper: TRACE Back from the Future: A Probabilistic Reasoning Approach to Controllable Language Generation (ICML 2025)
- HuggingFace Model: gwenweng/hmm-gpt2-large
- GitHub Repository: yidouweng/trace
- Perspective API Docs: developers.perspectiveapi.com
- PyTorch Installation: pytorch.org/get-started