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/ref_torch.py from Red-fuchs/ncm-modular: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/Red-fuchs/ncm-modular/resolve/main/src/ncm_modular/ref_torch.py
- Command line
-
hf download hf://Red-fuchs/ncm-modular/src/ncm_modular/ref_torch.py
-
curl -L -o ref_torch.py https://huggingface.co/Red-fuchs/ncm-modular/resolve/main/src/ncm_modular/ref_torch.py
1.18 kB
| """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 | |