- AutoRegressiveLM 注册名改为 autoregressive_lm - 新增 EmbeddingEncoder 支持 mean/cls/last pooling - ModelConfig 增加 pooling_type / normalize_embeddings 字段 - 导入、注释、测试全部同步更新 |
||
|---|---|---|
| .github | ||
| assets | ||
| astrai | ||
| scripts | ||
| tests | ||
| .dockerignore | ||
| .gitattributes | ||
| .gitignore | ||
| CONTRIBUTING.md | ||
| Dockerfile | ||
| LICENSE | ||
| README.md | ||
| docker-compose.yml | ||
| pyproject.toml | ||
README.md
A lightweight Transformer training & inference framework
📖 Table of Contents
English
Features
- 🚀 High Performance: Optimized for both training and inference with efficient parallelization.
- 🔧 Flexible: Support for seq/sft/dpo/grpo training, customizable model architectures.
- 💡 Easy to Use: Simple API with comprehensive examples and demos.
- 📦 Lightweight: Minimal dependencies, easy to deploy.
- 🔬 Research‑Friendly: Modular design, easy to experiment with new ideas.
- 🤗 HuggingFace-Style API: AutoModel/AutoTokenizer APIs inspired by HuggingFace for easy model and tokenizer loading.
- 🔌 Dual API Compatibility: Supports both OpenAI and Anthropic chat completion APIs out of the box.
Quick Start
Installation
git clone https://github.com/ViperEkura/AstrAI.git
cd AstrAI
pip install -e .
For development dependencies:
pip install -e ".[dev]"
Download Pre-trained Model
Download pre-trained model weights (1B bilingual checkpoint) to params/:
python scripts/demo/download.py
Or download manually from HuggingFace into params/.
Train a Model
export CUDA_VISIBLE_DEVICES=0,1,2,3
nohup python scripts/tools/train.py \
--nprocs=4 \
--train_type=pt \
--data_root_path=/path/to/dataset \
--param_path=/path/to/model \
--batch_per_device=4 \
--grad_accum_steps=8 \
--warmup_ratio=0.05 \
--max_lr=1e-4 \
--max_grad_norm=1.0 \
--adamw_beta1=0.95 \
--adamw_beta2=0.99 \
--adamw_weight_decay=0.01 \
--window_size=2048 \
--ckpt_interval=10000 \
--ckpt_dir=./checkpoint \
--random_seed=3407 \
--label_smoothing=0.05 \
> out.log 2> err.log &
Full reference at Parameter Guide.
Generate Text
python scripts/tools/generate.py \
--param_path /path/to/model \
--input_json_file /path/to/input.json \
--output_json_file /path/to/output.json
Docker
Build and run with Docker (recommended for GPU environments):
# Build image
docker build -t astrai:latest .
# Run with GPU support
docker run --gpus all -it astrai:latest
# Run with specific GPUs
docker run --gpus '"device=0,1"' -it astrai:latest
# Run inference server
docker run --gpus all -p 8000:8000 astrai:latest \
python -m scripts.tools.server --port 8000 --device cuda
# Run with volume mount for data
docker run --gpus all -v /path/to/data:/data -it astrai:latest
# Docker Compose (GPU, default)
docker compose up -d
# Docker Compose (CPU only)
docker compose --profile cpu up -d
Note:
--gpus allis required for CUDA support. Without it,torch.cuda.is_available()will returnFalse.
Start HTTP Server
Start the inference server with OpenAI and Anthropic-compatible HTTP API:
python -m scripts.tools.server --port 8000 --device cuda
Make requests:
# OpenAI-compatible
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 512
}'
# OpenAI-compatible streaming
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "Tell a story"}],
"stream": true,
"max_tokens": 500
}'
# Anthropic-compatible
curl -X POST http://localhost:8000/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "astrai",
"system": "You are a helpful assistant.",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 512
}'
# Anthropic-compatible streaming with stop sequences
curl -X POST http://localhost:8000/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "astrai",
"messages": [{"role": "user", "content": "Write a story"}],
"max_tokens": 500,
"stream": true,
"stop_sequences": ["The end"]
}'
# Health check
curl http://localhost:8000/health
Demo
Check out the demos in the scripts/demo/ folder:
# Download pre‑processed data (required before running demos)
python scripts/demo/download.py
# Interactive streaming chat
python scripts/demo/stream_chat.py
# Batch generation
python scripts/demo/generate_batch.py
# Auto‑regressive generation
python scripts/demo/generate_ar.py
Watch a video walkthrough on bilibili.
Documentation
| Document | Description |
|---|---|
| Parameter Guide | Training & inference parameters |
| Architecture | System architecture, class diagram & design patterns |
| Training | Training loop, strategies & formulas |
| Inference | KVCache, continuous batching, sampling & HTTP API |
| Data Flow | Data pipeline, storage backends & dataset architecture |
Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository.
- Create a feature branch.
- Commit your changes.
- Open a Pull Request.
For major changes, please open an issue first to discuss what you would like to change.
Community
- GitHub Issues: Issue Tracker
- Discussions: GitHub Discussions
- HuggingFace: Model Hub
License
This project is licensed under the GPL-3.0 License.