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/seam/data.py from Red-fuchs/ncm-modular: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/Red-fuchs/ncm-modular/resolve/main/src/ncm_modular/seam/data.py
- Command line
-
hf download hf://Red-fuchs/ncm-modular/src/ncm_modular/seam/data.py
-
curl -L -o data.py https://huggingface.co/Red-fuchs/ncm-modular/resolve/main/src/ncm_modular/seam/data.py
1.88 kB
| """tokenise blocks, codec codes (cached), pair/prefix arrays per variant.""" | |
| import os, json, numpy as np, mlx.core as mx | |
| from gen2 import * | |
| def tok_block(t): return (bpe.encode(t)[:L - 1] + [EOS]) | |
| def load_split(name, fc, cache=True, limit=0): | |
| S = json.load(open(f"{DATA}/{name}.json")) | |
| if limit: S, cache = S[:limit], False | |
| ids, sidx, bidx = [], [], [] | |
| for si, s in enumerate(S): | |
| for bi, b in enumerate(s["blocks"]): ids.append(tok_block(b)); sidx.append(si); bidx.append(bi) | |
| arr = np.array([i + [PAD] * (L - len(i)) for i in ids], np.int32) | |
| f = f"{DATA}/codes_{name}.npy" | |
| if cache and os.path.exists(f) and len(np.load(f, mmap_mode='r')) == len(arr): codes = np.load(f) | |
| else: | |
| out = [] | |
| for i in range(0, len(arr), 128): | |
| cs = fc.encode(mx.array(arr[i:i + 128])); out.append(np.array(mx.concatenate(cs, 1)).astype(np.int16)); mx.clear_cache() | |
| codes = np.concatenate(out) | |
| if cache: np.save(f, codes) | |
| return S, arr, codes, np.array(sidx), np.array(bidx) | |
| def pairs(v, S, arr, codes, sidx, bidx, ntable_from="gold"): | |
| """one pair per (story, block n>=1): prefix array (P,), target block row.""" | |
| start = {} | |
| for r, (s, b) in enumerate(zip(sidx, bidx)): | |
| if b == 0: start[s] = r | |
| import re | |
| SR = re.compile(r"(?<![\w'])(?:John|Mary|David|Sarah|James|Peter|Emma|Mark)(?![\w'])") | |
| P, T = [], [] | |
| for s, st in enumerate(S): | |
| seen, r0 = [], start[s] | |
| for n in range(1, len(st["blocks"])): | |
| for m in SR.findall(st["blocks"][n - 1]): | |
| if m not in seen: seen.append(m) | |
| prev = [t for t in arr[r0 + n - 1].tolist() if t not in (EOS, PAD)] | |
| hist = [codes[r0 + j][:CPB] for j in range(max(0, n - MB), n)] | |
| P.append(make_prefix(v, prev, seen, hist)); T.append(r0 + n) | |
| return np.stack(P), np.array(T) | |