Text Generation
Transformers
Safetensors
gpt2
latent-reasoning
codi
slpo
reinforcement-learning
text-generation-inference
Instructions to use ModalityDance/slpo-codi-gpt2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ModalityDance/slpo-codi-gpt2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ModalityDance/slpo-codi-gpt2")# Load model directly from transformers import AutoTokenizer, LatentCODIGPT2 tokenizer = AutoTokenizer.from_pretrained("ModalityDance/slpo-codi-gpt2") model = LatentCODIGPT2.from_pretrained("ModalityDance/slpo-codi-gpt2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ModalityDance/slpo-codi-gpt2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ModalityDance/slpo-codi-gpt2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ModalityDance/slpo-codi-gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ModalityDance/slpo-codi-gpt2
- SGLang
How to use ModalityDance/slpo-codi-gpt2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ModalityDance/slpo-codi-gpt2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ModalityDance/slpo-codi-gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ModalityDance/slpo-codi-gpt2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ModalityDance/slpo-codi-gpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ModalityDance/slpo-codi-gpt2 with Docker Model Runner:
docker model run hf.co/ModalityDance/slpo-codi-gpt2
Add runnable load-and-generate usage snippet
Browse files
README.md
CHANGED
|
@@ -37,28 +37,78 @@ Deterministic accuracy with dropout disabled and learned stop gate:
|
|
| 37 |
## Related
|
| 38 |
|
| 39 |
- Code: [ModalityDance/SLPO](https://github.com/ModalityDance/SLPO)
|
|
|
|
| 40 |
- Base model: [ModalityDance/latent-tts-codi](https://huggingface.co/ModalityDance/latent-tts-codi)
|
| 41 |
- Sibling: [ModalityDance/slpo-coconut-gpt2](https://huggingface.co/ModalityDance/slpo-coconut-gpt2)
|
| 42 |
-
-
|
| 43 |
|
| 44 |
## Installation
|
| 45 |
|
| 46 |
```bash
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
```
|
| 49 |
|
| 50 |
## Quick Start
|
| 51 |
|
| 52 |
-
|
| 53 |
|
| 54 |
```bash
|
| 55 |
CKPT=checkpoints/slpo-codi-gpt2 \
|
| 56 |
MODEL_TYPE=codi STOP_POLICY=gate \
|
| 57 |
-
MAX_LATENT_LENGTH=12 \
|
|
|
|
| 58 |
bash scripts/eval.sh
|
| 59 |
```
|
| 60 |
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
## Citation
|
| 64 |
|
|
|
|
| 37 |
## Related
|
| 38 |
|
| 39 |
- Code: [ModalityDance/SLPO](https://github.com/ModalityDance/SLPO)
|
| 40 |
+
- Project page: [modalitydance.github.io/SLPO](https://modalitydance.github.io/SLPO/)
|
| 41 |
- Base model: [ModalityDance/latent-tts-codi](https://huggingface.co/ModalityDance/latent-tts-codi)
|
| 42 |
- Sibling: [ModalityDance/slpo-coconut-gpt2](https://huggingface.co/ModalityDance/slpo-coconut-gpt2)
|
| 43 |
+
- Collection: [ModalityDance/SLPO](https://huggingface.co/collections/ModalityDance/slpo)
|
| 44 |
|
| 45 |
## Installation
|
| 46 |
|
| 47 |
```bash
|
| 48 |
+
git clone https://github.com/ModalityDance/SLPO.git
|
| 49 |
+
cd SLPO
|
| 50 |
+
pip install -r requirements.txt # plus a CUDA PyTorch build
|
| 51 |
+
hf download ModalityDance/slpo-codi-gpt2 --local-dir checkpoints/slpo-codi-gpt2
|
| 52 |
```
|
| 53 |
|
| 54 |
## Quick Start
|
| 55 |
|
| 56 |
+
Batched eval (paper Acc settings):
|
| 57 |
|
| 58 |
```bash
|
| 59 |
CKPT=checkpoints/slpo-codi-gpt2 \
|
| 60 |
MODEL_TYPE=codi STOP_POLICY=gate \
|
| 61 |
+
STOP_GATE_THRESHOLD=0.7 MAX_LATENT_LENGTH=12 \
|
| 62 |
+
DATA=data/gsm_test.json \
|
| 63 |
bash scripts/eval.sh
|
| 64 |
```
|
| 65 |
|
| 66 |
+
Minimal Python (from the repo root; needs the SLPO latent generation stack):
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
import torch
|
| 70 |
+
from transformers import AutoTokenizer
|
| 71 |
+
|
| 72 |
+
from src.models.generation import LatentGenerationMixin, LatentGenerationConfig
|
| 73 |
+
from src.paths import get_model_class
|
| 74 |
+
|
| 75 |
+
model_id = "ModalityDance/slpo-codi-gpt2"
|
| 76 |
+
backbone_cls = get_model_class("codi")
|
| 77 |
+
|
| 78 |
+
class LatentModel(backbone_cls, LatentGenerationMixin):
|
| 79 |
+
pass
|
| 80 |
+
|
| 81 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 82 |
+
if tokenizer.pad_token is None:
|
| 83 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 84 |
+
|
| 85 |
+
model = LatentModel.from_pretrained(model_id)
|
| 86 |
+
model.eval()
|
| 87 |
+
|
| 88 |
+
question = (
|
| 89 |
+
"Janet's ducks lay 16 eggs per day. She eats three for breakfast every morning "
|
| 90 |
+
"and bakes muffins for her friends every day with four. She sells the remainder "
|
| 91 |
+
"at the farmers' market daily for $2 per fresh duck egg. "
|
| 92 |
+
"How much in dollars does she make every day at the farmers' market?"
|
| 93 |
+
)
|
| 94 |
+
prompt = question + "<|start-latent|>"
|
| 95 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 96 |
+
|
| 97 |
+
gen_cfg = LatentGenerationConfig(
|
| 98 |
+
stop_policy="gate",
|
| 99 |
+
max_latent_length=12,
|
| 100 |
+
stop_gate_threshold=0.7,
|
| 101 |
+
max_new_tokens=128,
|
| 102 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 103 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 104 |
+
bos_token_id=tokenizer.bos_token_id,
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
with torch.no_grad():
|
| 108 |
+
output = model.generate(**inputs, generation_config=gen_cfg)
|
| 109 |
+
sequences = output.sequences if hasattr(output, "sequences") else output
|
| 110 |
+
print(tokenizer.decode(sequences[0], skip_special_tokens=True))
|
| 111 |
+
```
|
| 112 |
|
| 113 |
## Citation
|
| 114 |
|