dd101bb commited on
Commit
9c1b8f7
·
verified ·
1 Parent(s): a8c60d7

Add runnable load-and-generate usage snippet

Browse files
Files changed (1) hide show
  1. README.md +55 -5
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
- - Latent TTS collection: [Latent TTS](https://huggingface.co/collections/ModalityDance/latent-tts-69635ae5a732662b4d41225f)
43
 
44
  ## Installation
45
 
46
  ```bash
47
- huggingface-cli download ModalityDance/slpo-codi-gpt2 --local-dir checkpoints/slpo-codi-gpt2
 
 
 
48
  ```
49
 
50
  ## Quick Start
51
 
52
- Inference uses the custom latent generation stack from the [SLPO](https://github.com/ModalityDance/SLPO) repository:
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
- Set `stop_gate_threshold=0.7` to match the paper evaluation.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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