A step-by-step guide to using TopoGPT3 from installation to custom training.
Project URL: https://github.com/grisuno/TopoGPT3
- Installation
- Your First Inference
- Understanding the Output
- Using HRM Inference
- Preparing Training Data
- Training from Scratch
- Resuming Training
- Evaluating on Holdout
- Customizing the Model Scale
- Interpreting Training Diagnostics
- Using the Python API
- Generating Synthetic Data
- Next Steps
git clone https://github.com/grisuno/TopoGPT3.git
cd TopoGPT3
python3 -m venv env
source env/bin/activate
pip install -e ".[train]"python -c "from topogpt3 import __version__; print(__version__)"Expected output: 0.1.0
Checkpoints are hosted on Hugging Face:
mkdir -p checkpoints_topogpt3/last
# Download model.safetensors and state.json from:
# https://huggingface.co/grisiscomeback/TopoGPT3/tree/main/checkpoints_topogpt3/lasttopogpt3-infer --prompt "def fibonacci(n):\n """Return the nth Fibonacci number."""\n" --max-new 100Create first_inference.py:
from topogpt3 import InferenceSettings, InferencePipeline
settings = InferenceSettings(
checkpoint_dir="checkpoints_topogpt3",
checkpoint_name="last",
prompt="def fibonacci(n):\n",
max_new_tokens=100,
temperature=0.3,
)
report = InferencePipeline(settings).execute()
print(report.output)Run it:
python first_inference.pyThe GenerationReport object contains:
output: the generated text stringtokens_generated: count of new tokens producedtime_seconds: generation wall time
You can inspect these fields for benchmarking:
print(f"Generated {report.tokens_generated} tokens in {report.time_seconds:.2f}s")HRM adds iterative latent refinement to standard decoding.
topogpt3-infer-hrm \
--prompt "def factorial(n):\n" \
--max-new 100 \
--hrm-h-iters 2 \
--hrm-l-iters 3 \
--hrm-l-window 2from topogpt3 import (
HRMInferencePipeline,
HRMInferenceSettings,
RecursiveReasoningConfig,
)
settings = HRMInferenceSettings(
prompt="def factorial(n):\n",
checkpoint_dir="checkpoints_topogpt3",
max_new_tokens=100,
reasoning=RecursiveReasoningConfig(
max_high_level_iters=2,
max_low_level_iters=3,
low_level_window=2,
),
)
report = HRMInferencePipeline(settings).execute()
print(report.output)HRM is slower than standard inference but provides diagnostics on latent refinement dynamics.
Before training, download and tokenize the four curriculum datasets:
topogpt3-train --prepare-dataThis creates cached tokenized datasets in the data/ directory. It only needs to be run once.
topogpt3-train --train --scale smallfrom topogpt3 import TopoGPT3Config, TopoGPT3Trainer
config = TopoGPT3Config(SCALE="small")
trainer = TopoGPT3Trainer(config)
trainer.prepare_all()
trainer.run()Training proceeds automatically through the four tiers. Checkpoints are saved to checkpoints_topogpt3/last/.
To resume from a specific tier (for example, tier 2):
topogpt3-train --train --start-tier 2The trainer loads the latest checkpoint and continues from the requested tier, even if the state file marks it as completed.
After training, evaluate generalization on the combined holdout set:
topogpt3-train --eval-holdoutThis reports holdout loss, accuracy, and perplexity without updating model weights.
The SCALE parameter controls model size. Options are micro, small, medium, and gpt2.
from topogpt3 import TopoGPT3Config
config = TopoGPT3Config(SCALE="micro") # smallest, for CPU
config = TopoGPT3Config(SCALE="small") # default, ~24.5M parameters
config = TopoGPT3Config(SCALE="medium") # larger, more VRAM
config = TopoGPT3Config(SCALE="gpt2") # GPT-2 reference dimensionsIf you run out of memory, switch to micro.
During training, the console prints metrics like:
[step 1000] loss: 2.168 | acc: 60.08% | rank: 16 | W: 0.55 | Delta_F: 1.347e-3
What these mean:
- loss / acc: standard language modeling metrics.
- rank: dominant subspace dimension (stable at 16 is good).
- W: net angular drift. Bounded values suggest coherent phase evolution.
- Delta_F: Fisher spectral gap. Positive values indicate a stable functional subspace.
These diagnostics are observational, not rigorous invariants. Use them to understand optimization structure beyond scalar loss.
After pip install -e ., import the public API:
from topogpt3 import (
InferenceSettings,
InferencePipeline,
HRMInferenceSettings,
HRMInferencePipeline,
RecursiveReasoningConfig,
TopoGPT3Config,
TopoGPT3Trainer,
)app.py at the repository root is a complete, runnable example that wires all three modes (standard inference, HRM inference, training) behind a single CLI. Copy it into your own project and adapt.
TopoGPT3 includes synthetic_dataset.py, which turns source files into instruction-tuning data using an external LLM.
export GROQ_API_KEY="your-key"
python synthetic_dataset.py \
--provider groq \
--model llama-3.3-70b-versatile \
--paths-file my_files.txt \
--output data/synthetic.jsonlexport OPENROUTER_API_KEY="your-key"
python synthetic_dataset.py \
--provider openrouter \
--model anthropic/claude-3.5-sonnet \
--paths-file my_files.txt \
--output data/synthetic_claude.jsonlThe script supports SHA256 deduplication, resumable progress via a manifest, and threaded batch processing.
- Explore the Command Cheatsheet for quick reference.
- Read Essential Concepts to understand the theory.
- Review the Technical Paper for full experimental results.
- See Comparison to understand how TopoGPT3 fits in the landscape of small models.
License: GPL v3 | Author: grisun0