Text Generation
Transformers
Safetensors
English
gated_deltanet
gated-deltanet
linear-attention
recurrent
long-context
research
Instructions to use LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft")# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft
- SGLang
How to use LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft 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 "LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft" \ --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": "LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft", "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 "LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft" \ --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": "LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft with Docker Model Runner:
docker model run hf.co/LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft
Add CPU and GPU usage examples
Browse files
README.md
CHANGED
|
@@ -45,6 +45,103 @@ This checkpoint is intended for research on:
|
|
| 45 |
- recurrent-state contamination during long generation
|
| 46 |
- Reference-State Reset with Rolling Replay, a GDN/RNN adaptation of the R-SWA idea
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
## Known Results
|
| 49 |
|
| 50 |
1B 32K answer-focused run. MQAR likelihood improved 4K/16K but damaged 1K and did not transfer to 32K/64K: final 1K 0.0000, 2K 0.0625, 4K 0.1562, 8K 0.0625, 16K 0.1875, 32K 0.0000, 64K 0.0000.
|
|
|
|
| 45 |
- recurrent-state contamination during long generation
|
| 46 |
- Reference-State Reset with Rolling Replay, a GDN/RNN adaptation of the R-SWA idea
|
| 47 |
|
| 48 |
+
## Usage
|
| 49 |
+
|
| 50 |
+
These checkpoints use the FLA Gated DeltaNet implementation. In the current
|
| 51 |
+
Long-GDN environment, plain `GatedDeltaNetForCausalLM.from_pretrained()` can
|
| 52 |
+
hit a Transformers 5.x tied-weight metadata issue. The robust path is to patch
|
| 53 |
+
the FLA tied-weight metadata before loading.
|
| 54 |
+
|
| 55 |
+
Install/runtime requirements:
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
pip install torch transformers safetensors huggingface_hub
|
| 59 |
+
# plus an FLA package/source tree that provides:
|
| 60 |
+
# fla.models.gated_deltanet.GatedDeltaNetForCausalLM
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
### CPU Example
|
| 64 |
+
|
| 65 |
+
```python
|
| 66 |
+
import torch
|
| 67 |
+
from transformers import AutoTokenizer
|
| 68 |
+
from fla.models.gated_deltanet import GatedDeltaNetForCausalLM
|
| 69 |
+
|
| 70 |
+
repo_id = "LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft"
|
| 71 |
+
|
| 72 |
+
# Transformers 5.x compatibility patch for the installed FLA class.
|
| 73 |
+
if isinstance(getattr(GatedDeltaNetForCausalLM, "_tied_weights_keys", None), list):
|
| 74 |
+
GatedDeltaNetForCausalLM._tied_weights_keys = {
|
| 75 |
+
"lm_head.weight": "model.embeddings.weight"
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id, use_fast=True)
|
| 79 |
+
model = GatedDeltaNetForCausalLM.from_pretrained(
|
| 80 |
+
repo_id,
|
| 81 |
+
torch_dtype=torch.float32,
|
| 82 |
+
)
|
| 83 |
+
model.eval()
|
| 84 |
+
|
| 85 |
+
prompt = "A special magic number is 12345. What is the special magic number?"
|
| 86 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 87 |
+
with torch.no_grad():
|
| 88 |
+
output = model.generate(
|
| 89 |
+
**inputs,
|
| 90 |
+
max_new_tokens=32,
|
| 91 |
+
do_sample=False,
|
| 92 |
+
)
|
| 93 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
### Single-GPU bf16 Example
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
import torch
|
| 100 |
+
from transformers import AutoTokenizer
|
| 101 |
+
from fla.models.gated_deltanet import GatedDeltaNetForCausalLM
|
| 102 |
+
|
| 103 |
+
repo_id = "LLM-OS-Models/gdn1-longctx-1b-32k-answer-ft"
|
| 104 |
+
|
| 105 |
+
if isinstance(getattr(GatedDeltaNetForCausalLM, "_tied_weights_keys", None), list):
|
| 106 |
+
GatedDeltaNetForCausalLM._tied_weights_keys = {
|
| 107 |
+
"lm_head.weight": "model.embeddings.weight"
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id, use_fast=True)
|
| 111 |
+
model = GatedDeltaNetForCausalLM.from_pretrained(
|
| 112 |
+
repo_id,
|
| 113 |
+
torch_dtype=torch.bfloat16,
|
| 114 |
+
).to("cuda")
|
| 115 |
+
model.eval()
|
| 116 |
+
|
| 117 |
+
prompt = "Reference facts:\n- key_alpha: value_123\n\nQuestion: key_alpha?\nAnswer:"
|
| 118 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 119 |
+
with torch.no_grad():
|
| 120 |
+
output = model.generate(
|
| 121 |
+
**inputs,
|
| 122 |
+
max_new_tokens=32,
|
| 123 |
+
do_sample=False,
|
| 124 |
+
)
|
| 125 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
### Long-GDN Local Loader
|
| 129 |
+
|
| 130 |
+
The project repository includes a more defensive loader at
|
| 131 |
+
`scripts/gdn1_common.py::load_gdn1_causal_lm`. It handles the compatibility
|
| 132 |
+
patch and older public-checkpoint key conversion used in local experiments.
|
| 133 |
+
|
| 134 |
+
```python
|
| 135 |
+
from pathlib import Path
|
| 136 |
+
import torch
|
| 137 |
+
from transformers import AutoTokenizer
|
| 138 |
+
from scripts.gdn1_common import load_gdn1_causal_lm
|
| 139 |
+
|
| 140 |
+
repo_or_local_path = Path("path/to/downloaded/checkpoint")
|
| 141 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_or_local_path, use_fast=True)
|
| 142 |
+
model = load_gdn1_causal_lm(repo_or_local_path, torch_dtype=torch.bfloat16).to("cuda")
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
## Known Results
|
| 146 |
|
| 147 |
1B 32K answer-focused run. MQAR likelihood improved 4K/16K but damaged 1K and did not transfer to 32K/64K: final 1K 0.0000, 2K 0.0625, 4K 0.1562, 8K 0.0625, 16K 0.1875, 32K 0.0000, 64K 0.0000.
|