AkaliKong/MiniOneRec
Minimal reproduction of OneRec
MiniOneRec – Open‑Source Framework for Generative Recommendation
What it is
- A research‑grade Python library that lets you build a generative recommender system that works like a language model: items are turned into short semantic tokens (SIDs) and the model learns to generate the next token for a user.
- The pipeline covers the whole life‑cycle:
- SID construction – encode each product (title + description) with a frozen text encoder, then quantise the embedding with a Residual‑Quantized VAE (RQ‑VAE) or several RQ‑Kmeans variants.
- Supervised Fine‑Tuning (SFT) – treat a user’s chronological interaction list as a token sequence and train the LLM to predict the next SID, while also learning language‑alignment objectives that map between natural language and SID space.
- Recommendation‑oriented Reinforcement Learning (RL) – polish the SFT model with GRPO‑style RL, using a reward that mixes binary correctness, rank‑awareness and optional collaborative‑filtering scores. Constrained beam search guarantees that every generated SID is valid and unique.
Why it matters
- Bridges large‑language‑model knowledge (world facts, reasoning) with the discrete item space of recommender systems.
- Provides a fully open‑source end‑to‑end stack (data processing, tokenisation, training scripts, evaluation) that previously existed only in proprietary code.
- Designed to run on 4–8 modern GPUs (A100/H100) and includes multi‑GPU acceleration for the heavy text‑to‑embedding step.
Key components
| Component | Purpose | Main files |
|---|---|---|
| SID construction | Turn raw item text into compact semantic IDs (SIDs) using RQ‑VAE, RQ‑Kmeans, constrained‑Kmeans, etc. | rq/rqvae.py, rq/rqkmeans_faiss.py, rq/rqkmeans_constrained.py, rq/rqkmeans_plus.py, generation scripts in rq/ |
| Data pipeline | Load Amazon‑style datasets, filter, split, and produce the tokenised format used by SFT/RL. | data.py, convert_dataset*.py, preprocessing shells under data/ |
| Supervised fine‑tuning | Next‑token prediction on user histories, with optional value‑aware loss (GPR). | sft.py, sft_gpr.py, minionerec_trainer.py |
| Reinforcement learning | GRPO‑based policy optimisation for recommendation, with KL regularisation and group‑normalised rewards. | rl.py, rl_gpr.py |
| Evaluation | Offline Top‑K metrics (HR@K, NDCG@K). | evaluate.py, evaluate.sh |
| Logit processing | Constrained decoding to keep generated SIDs valid. | LogitProcessor.py |
Installation (quick)
# 1. Clone
git clone https://github.com/AkaliKong/MiniOneRec.git && cd MiniOneRec
# 2. Create env (Python 3.11+)
conda create -n minionerec python=3.11 -y && conda activate minionerec
# 3. Install deps
pip install -r requirements.txt
The repo lists all required packages (torch, transformers, accelerate, faiss‑gpu, etc.).
Typical workflow
- Prepare data – download an Amazon review split (e.g., 2018 Industrial), run the provided
data/amazon18_data_process.shto filter and produce*.emb‑qwen‑td.npy. - Encode items –
bash rq/amazon_text2emb.shuses a frozen PLM (e.g., Qwen) to generate embeddings. - Build SIDs – choose a method (RQ‑VAE, RQ‑Kmeans+, constrained‑Kmeans, FLASH, etc.) and run the corresponding training script (
rq/rqvae.sh,rqkmeans_constrained.sh, …). Then generate the index JSON withpython rq/generate_indices.py. - Convert dataset –
python convert_dataset.pycreates the token‑level training files. - Supervised fine‑tuning –
bash sft.sh(orsft_gpr.pyfor value‑aware loss) trains the LLM on the SID sequences. - RL polishing –
bash rl.shruns the GRPO‑based reinforcement learning stage. - Evaluate –
bash evaluate.shreports HR@K / NDCG@K on a held‑out test set.
Supported LLM back‑ends
- Any HuggingFace model that can be loaded as a causal language model (e.g., Qwen2.5‑base, LLaMA, etc.).
- API‑based providers (OpenAI, DeepSeek, MiniMax) for auxiliary text‑enrichment tasks; configure via an
api_infodict.
Hardware requirements
- 4–8 GPUs with ≥80 GB memory for full‑scale training (the repo mentions A100/H100). Smaller experiments can run on a single GPU with reduced batch sizes.
Roadmap highlights
- Additional SID construction algorithms (R‑VQ, PLUM‑based RQ‑VAE‑v2).
- MiniOneRec‑Think – a future module that adds dialogue and reasoning capabilities on top of recommendation.
- Expanded dataset catalog (Yelp, etc.).
Community & citation
- Developed by USTC’s LDS, AlphaLab, and NExT research groups.
- The authors ask to cite the arXiv technical report (arXiv:2510.24431) and related papers.
Bottom line: MiniOneRec is a genuine, research‑focused open‑source framework that lets AI practitioners experiment with large‑language‑model‑driven recommender systems—from tokenising items to RL‑based policy optimisation—using publicly available datasets and commodity GPU clusters.
Related
- Project
- Project
- Project
- Project
- Project