This repository contains ready-to-run inference entry points for HEP chat models.
Models are listed in models.json, so new trained models can be added without
rewriting the app, terminal chat, batch runner, or download helper.
Fast local mode uses shorter deterministic replies and skips chat history so
each turn has less prompt to process:
python terminal_chat.py --device mps --fast
MPS does not support bfloat16. This repo loads LoRA adapters on CPU first and
then moves the model to MPS in a supported dtype.
Inside the chat, use /clear to reset history and /exit to quit.
Apple Silicon Arm64 Environment
If diagnostics reports platform.machine as x86_64 on an Apple Silicon Mac,
create an arm64 virtual environment. The repo ignores .venv-arm64/ so it can
live beside the code:
Code agents should execute model inference themselves with run_questions.py,
not drive terminal_chat.py or the Gradio UI. The question file is one question
per non-empty line. For blank-line separated multi-line questions:
The output is JSONL. The first record is run metadata unless --no-metadata is
set. Answer records include question, answer, model_name, base_model,
adapter, model_mode, device, and created_at fields. See AGENTS.md for
the short operational guide intended for Claude, Codex, Copilot, and similar
code agents.
1{2"models":{3"my-new-hep-model":{4"base_model":"BASE_MODEL_REPO",5"adapter":"OPTIONAL_LORA_ADAPTER_REPO",6"description":"Short description for humans and agents."7}8}9}
If a model does not use a LoRA adapter, omit adapter and run it with
--model-mode base or MODEL_MODE=base.
Validation and Benchmarking
Run a single end-to-end smoke test:
python smoke_test.py --device mps --fast --text
Benchmark load time, latency, and output tokens per second:
Both commands emit JSON by default. Use smoke tests after changing model entries
or Python environments, and benchmark when comparing Mac MPS, CUDA, CPU, or
future quantized backends.
Copy-Paste Cluster Launch
Run these commands inside a GPU allocation, not on a login node:
The diagnostics output is JSON so code agents can parse it. Important fields:
summary.can_try_mps: this Python environment can try Apple Silicon GPU
summary.can_try_cuda: this Python environment can try NVIDIA CUDA GPU
summary.meets_minimum_disk: cache disk has enough free space to try one 7B model
summary.meets_recommended_disk: cache disk has comfortable free space
summary.meets_minimum_ram: system RAM meets the minimum for 7B inference
summary.meets_recommended_ram: system RAM is in the comfortable range
disk.cache_dir: where Hugging Face model files are expected
disk.cache_size_gb: current size of that model cache
packages: installed versions of Torch, Transformers, PEFT, NumPy, and related packages
simulation.enabled: whether any reported resource values were synthetic
memory.detected_total_ram_gb and disk.detected_free_gb: real values when simulation is used
Minimum requirements for the default 7B model:
Disk: 25 GB free for one clean model cache and Python environment
Apple Silicon Mac: 32 GB unified memory
NVIDIA CUDA GPU: 16 GB VRAM
CPU-only: 32 GB system RAM, but expect very slow inference
Python: 3.10+ with the packages in requirements.txt
Recommended requirements:
Disk: 50 GB free for cache growth, partial downloads, and future model variants
Apple Silicon Mac: 64 GB unified memory
NVIDIA CUDA GPU: 24 GB VRAM
CPU-only: 64 GB system RAM, still slow
On clusters: 75 GB+ in scratch/cache storage if trying multiple models
Why disk usage is this high:
Default 7B base model: about 15 GB
LoRA adapter: about 100 MB
Python environment: commonly 2-8 GB on Mac, 5-15 GB with CUDA packages
Hugging Face cache can keep partial downloads, locks, snapshots, and old revisions
Why memory usage is this high:
The current backend runs the default 7B model in fp16/bf16-style Transformers weights.
The base model is roughly 14 GB before runtime overhead.
KV cache grows with prompt length and generated tokens.
Apple Silicon uses unified memory, shared by the OS, Python, model weights, and GPU execution.
Performance guidance:
Use --fast for local Mac runs.
Keep terminal chat open across multiple questions to avoid reloading weights.
Reduce --max-new-tokens for faster replies and lower memory pressure.
Avoid compare_chat.py on memory-constrained machines; it loads two models.
On Apple Silicon, prefer an arm64 Python environment. If diagnostics show
platform.machine as x86_64, recreate the environment with an arm64
Python/Conda install for best local GPU performance.
Fixing Install Issues
If Gradio fails with ImportError: cannot import name 'HfFolder' from 'huggingface_hub', reinstall with the pinned requirements:
1curl http://localhost:8000/v1/chat/completions \2 -H "Content-Type: application/json"\3 -d '{
4 "model": "hep",
5 "messages": [
6 {"role": "user", "content": "For H to AA to photons, what Standard Model backgrounds should be considered?"}
7 ],
8 "max_tokens": 300
9 }'