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
File size: 1,179 Bytes
b5731a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | """Upstream PyTorch codec (CPU) loader. Needs torch, omegaconf, pyyaml and NCM_UPSTREAM=<HazyResearch/ncm checkout>."""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from paths import UPSTREAM
sys.path.insert(0, UPSTREAM) # checkout of github.com/HazyResearch/ncm (not vendored); provides models.vqvae
import torch, yaml
from omegaconf import OmegaConf
def load_state(path):
sd = torch.load(path, map_location="cpu", weights_only=True)
for k in ("state_dict", "model", "vqvae", "tokenizer"):
if isinstance(sd, dict) and k in sd and isinstance(sd[k], dict) and not torch.is_tensor(sd[k]): sd = sd[k]
return sd
def load_ref(d):
from models.vqvae import VQVAE
cfg = OmegaConf.load(f"{d}/config.yaml")
kw = OmegaConf.to_container(cfg.tokenizer.vqvae, resolve=True)
kw.pop("checkpoint_path", None)
kw["vector_quantizer_config"] = cfg.tokenizer.vqvae.vector_quantizer_config
m = VQVAE(**kw)
sd = load_state(f"{d}/tokenizer.pt")
sd = {k.removeprefix("module.").removeprefix("_orig_mod."): v for k, v in sd.items()}
print("load:", m.load_state_dict(sd, strict=False))
return m.eval(), cfg
|