Text Generation
MLX
English
German
next-concept-modeling
apple-silicon
diffusion-lm
research-code
negative-results
Instructions to use Red-fuchs/ncm-modular with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use Red-fuchs/ncm-modular with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("Red-fuchs/ncm-modular") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- MLX LM
How to use Red-fuchs/ncm-modular with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "Red-fuchs/ncm-modular" --prompt "Once upon a time"
- Atomic Chat
Download src/ncm_modular/parity.py from Red-fuchs/ncm-modular: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/Red-fuchs/ncm-modular/resolve/main/src/ncm_modular/parity.py
- Command line
-
hf download hf://Red-fuchs/ncm-modular/src/ncm_modular/parity.py
-
curl -L -o parity.py https://huggingface.co/Red-fuchs/ncm-modular/resolve/main/src/ncm_modular/parity.py
1.59 kB
| """Compare MLX codec vs torch dump.""" | |
| import sys, os, numpy as np, mlx.core as mx | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from paths import WORK | |
| import codec_mlx | |
| mx.set_default_device(mx.cpu) | |
| task = sys.argv[1] | |
| R = np.load(f"{WORK}/ref_{task}.npz") | |
| for dt, nm in [(mx.float32, "fp32"), (mx.float64, "fp64")]: | |
| c = codec_mlx.load(f"{WORK}/mlx/{task}", dt) | |
| x = mx.array(R["ids"]) | |
| z = c.embed(x); zq = z | |
| codes = c.encode(x); zh = c.cumulative(codes) | |
| mx.eval(codes, zh) | |
| # pre-quant latent | |
| print(f"--- {task} {nm}: pre-quant z max|diff| {np.abs(np.array(z) - R['z']).max():.2e}") | |
| off = 0 | |
| for k, cd in enumerate(codes): | |
| n = c.levels[k] | |
| ref = R["idx"][:, off:off + n]; off += n | |
| eq = (np.array(cd) == ref) | |
| print(f" level {k:2d} (len {n:2d}) codes equal {eq.mean()*100:6.2f}% zhat max|diff| {np.abs(np.array(zh[k]) - R['zh'][k]).max():.2e}") | |
| dec = np.stack([np.array(mx.argmax(c.decode_logits(h), -1)) for h in zh]) | |
| print(f" decoded ids per level equal: " + " ".join(f"{(dec[k]==R['dec'][k]).mean()*100:.1f}" for k in range(len(zh)))) | |
| print(f" final decoded ids equal: {(dec[-1]==R['dec_full']).mean()*100:.2f}%") | |
| # decode-only parity: feed torch codes into MLX decode | |
| cs, off = [], 0 | |
| for n in c.levels: cs.append(mx.array(R["idx"][:, off:off + n])); off += n | |
| dd = np.array(c.decode_codes(cs)) | |
| zz = c.cumulative(cs)[-1] | |
| print(f" decode-from-torch-codes: ids equal {(dd==R['dec_full']).mean()*100:.2f}% zhat max|diff| {np.abs(np.array(zz)-R['zh'][-1]).max():.2e}") | |