Text Generation
Transformers
Safetensors
Mongolian
rdt
traditional-mongolian
recurrent-depth-transformer
mamba
causal-lm
custom-code
custom_code
Instructions to use Montlok/DoL-1.2-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Montlok/DoL-1.2-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Montlok/DoL-1.2-Base", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Montlok/DoL-1.2-Base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Montlok/DoL-1.2-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Montlok/DoL-1.2-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Montlok/DoL-1.2-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Montlok/DoL-1.2-Base
- SGLang
How to use Montlok/DoL-1.2-Base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Montlok/DoL-1.2-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Montlok/DoL-1.2-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Montlok/DoL-1.2-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Montlok/DoL-1.2-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Montlok/DoL-1.2-Base with Docker Model Runner:
docker model run hf.co/Montlok/DoL-1.2-Base
Download Model/inference/cache.py from Montlok/DoL-1.2-Base: direct link, hf CLI and curl.
- Browser
- Download file 3.14 kB
-
https://huggingface.co/Montlok/DoL-1.2-Base/resolve/main/Model/inference/cache.py
- Command line
-
hf download hf://Montlok/DoL-1.2-Base/Model/inference/cache.py
-
curl -L -o cache.py https://huggingface.co/Montlok/DoL-1.2-Base/resolve/main/Model/inference/cache.py
3.14 kB
| # -*- coding: utf-8 -*- | |
| """Incremental decode caches for bit-exact autoregressive generation. | |
| The Daffodils RDT has exactly one cross-position operation: causal MLA | |
| attention. Every other sub-layer is per-position (mHC stream mixing, SwiGLU | |
| FFN, RMSNorm) or a sequential recurrence (the NaiveSSM Mamba scan). Therefore | |
| incremental decoding -- appending one token at a time while reusing frozen | |
| earlier state -- is *numerically identical* to re-running the full forward on | |
| the growing prefix, and these caches make that explicit. | |
| Two primitive caches: | |
| * :class:`MLACache` -- post-RoPE ``K``/``V`` of one attention call, grown by | |
| ``append``. Because each refinement pass of the Stage-2 loop is itself a | |
| fresh causal attention over the frozen earlier positions, every | |
| ``(step, layer)`` pair owns its own :class:`MLACache`. | |
| * :class:`MambaCache` -- the constant-size ``(conv_window, ssm_state)`` of one | |
| NaiveSSM layer, so the selective scan can be stepped one token at a time. | |
| :class:`DecodeCache` is a flat keyed container the orchestrators | |
| (``RDTForCausalLM`` / ``TwoStageCore``) populate lazily; keys encode the call | |
| site (e.g. ``"prelude.0"``, ``"stage1.2"``, ``"stage2.s3.l0"``, ``"coda.1"``). | |
| """ | |
| from __future__ import annotations | |
| from dataclasses import dataclass, field | |
| import torch | |
| class MLACache: | |
| """Per-attention-call key/value cache (post-RoPE, ``[B, H, T, head_dim]``).""" | |
| k: torch.Tensor | None = None | |
| v: torch.Tensor | None = None | |
| def length(self) -> int: | |
| return 0 if self.k is None else self.k.shape[-2] | |
| def append( | |
| self, k: torch.Tensor, v: torch.Tensor | |
| ) -> tuple[torch.Tensor, torch.Tensor]: | |
| """Append the new tokens' ``k``/``v`` and return the full cached tensors.""" | |
| if self.k is None: | |
| self.k, self.v = k, v | |
| else: | |
| self.k = torch.cat([self.k, k], dim=-2) | |
| self.v = torch.cat([self.v, v], dim=-2) | |
| return self.k, self.v | |
| class MambaCache: | |
| """Per-NaiveSSM constant-size recurrent state. | |
| ``conv_window`` holds the last ``d_conv - 1`` *pre-convolution* columns | |
| (shape ``[B, d_inner, d_conv - 1]``); ``ssm_state`` is the selective-scan | |
| state ``[B, nheads, headdim, d_state]`` in float32. | |
| """ | |
| conv_window: torch.Tensor | None = None | |
| ssm_state: torch.Tensor | None = None | |
| class DecodeCache: | |
| """Flat keyed container of per-layer caches for one decode stream.""" | |
| mla: dict[str, MLACache] = field(default_factory=dict) | |
| mamba: dict[str, MambaCache] = field(default_factory=dict) | |
| seq_len: int = 0 | |
| def mla_cache(self, key: str) -> MLACache: | |
| cache = self.mla.get(key) | |
| if cache is None: | |
| cache = self.mla[key] = MLACache() | |
| return cache | |
| def mamba_cache(self, key: str) -> MambaCache: | |
| cache = self.mamba.get(key) | |
| if cache is None: | |
| cache = self.mamba[key] = MambaCache() | |
| return cache | |
| def past_len(self) -> int: | |
| """Number of tokens already cached (0 before the prefill call).""" | |
| return self.seq_len | |