Any-to-Any
MLX
diffusion-lm
mixture-of-experts
multimodal
text-to-image
image-understanding
apple-silicon
llada
Instructions to use treadon/mlx-llada2-uni with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use treadon/mlx-llada2-uni with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir mlx-llada2-uni treadon/mlx-llada2-uni
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Upload test_generate.py with huggingface_hub
Browse files- test_generate.py +52 -0
test_generate.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Smoke test: run generate_text on a tiny randomly-initialized model.
|
| 2 |
+
|
| 3 |
+
Won't produce coherent text (weights are random) but verifies the loop runs.
|
| 4 |
+
"""
|
| 5 |
+
import mlx.core as mx
|
| 6 |
+
from llada2.model import LLaDA2Config, LLaDA2Model
|
| 7 |
+
from llada2.generate import generate_text
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def main():
|
| 11 |
+
cfg = LLaDA2Config(
|
| 12 |
+
vocab_size=200,
|
| 13 |
+
hidden_size=128,
|
| 14 |
+
intermediate_size=256,
|
| 15 |
+
num_hidden_layers=3,
|
| 16 |
+
num_attention_heads=4,
|
| 17 |
+
num_key_value_heads=2,
|
| 18 |
+
head_dim=32,
|
| 19 |
+
max_position_embeddings=128,
|
| 20 |
+
rope_theta=10000.0,
|
| 21 |
+
partial_rotary_factor=0.5,
|
| 22 |
+
num_experts=16,
|
| 23 |
+
num_shared_experts=1,
|
| 24 |
+
num_experts_per_tok=2,
|
| 25 |
+
n_group=4,
|
| 26 |
+
topk_group=2,
|
| 27 |
+
routed_scaling_factor=1.0,
|
| 28 |
+
moe_intermediate_size=64,
|
| 29 |
+
first_k_dense_replace=1,
|
| 30 |
+
pad_token_id=50,
|
| 31 |
+
mask_token_id=51,
|
| 32 |
+
eos_token_id=52,
|
| 33 |
+
)
|
| 34 |
+
model = LLaDA2Model(cfg)
|
| 35 |
+
mx.eval(model.parameters())
|
| 36 |
+
|
| 37 |
+
prompt_ids = mx.array([[10, 20, 30, 40]], dtype=mx.int32)
|
| 38 |
+
out = generate_text(
|
| 39 |
+
model, prompt_ids,
|
| 40 |
+
gen_length=16, block_length=8, steps_per_block=4,
|
| 41 |
+
temperature=0.0, threshold=0.5,
|
| 42 |
+
mask_token_id=cfg.mask_token_id, eos_token_id=cfg.eos_token_id,
|
| 43 |
+
verbose=True,
|
| 44 |
+
)
|
| 45 |
+
mx.eval(out)
|
| 46 |
+
print(f"output shape: {out.shape}")
|
| 47 |
+
print(f"output ids: {out[0].tolist()}")
|
| 48 |
+
print("OK: generation loop completed")
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
main()
|