Text Generation
Transformers
Safetensors
PyTorch
English
muddpythia
causal-lm
muddformer
custom_code
Instructions to use Caiyun-AI/MUDDPythia-1.4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Caiyun-AI/MUDDPythia-1.4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Caiyun-AI/MUDDPythia-1.4B", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Caiyun-AI/MUDDPythia-1.4B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Caiyun-AI/MUDDPythia-1.4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Caiyun-AI/MUDDPythia-1.4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Caiyun-AI/MUDDPythia-1.4B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Caiyun-AI/MUDDPythia-1.4B
- SGLang
How to use Caiyun-AI/MUDDPythia-1.4B 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 "Caiyun-AI/MUDDPythia-1.4B" \ --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": "Caiyun-AI/MUDDPythia-1.4B", "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 "Caiyun-AI/MUDDPythia-1.4B" \ --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": "Caiyun-AI/MUDDPythia-1.4B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Caiyun-AI/MUDDPythia-1.4B with Docker Model Runner:
docker model run hf.co/Caiyun-AI/MUDDPythia-1.4B
Add pipeline tag and library_name (#1)
Browse files- Add pipeline tag and library_name (2219483126f03360ab4a7e2557d3da7a4551c56a)
Co-authored-by: Niels Rogge <nielsr@users.noreply.huggingface.co>
README.md
CHANGED
|
@@ -1,75 +1,78 @@
|
|
| 1 |
-
---
|
| 2 |
-
language:
|
| 3 |
-
- en
|
| 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 |
-
|
| 29 |
-
import
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
torch.
|
| 45 |
-
torch._inductor.config
|
| 46 |
-
torch.
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: mit
|
| 5 |
+
library_name: transformers
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
+
tags:
|
| 8 |
+
- pytorch
|
| 9 |
+
- causal-lm
|
| 10 |
+
- muddformer
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
In comparison with Pythia-1.4B, MUDDPythia-1.4B is a pretrained language model on the Pile with 300B tokens, which uses a simple yet effective method to address the limitations of residual connections and enhance cross-layer information flow in Transformers. Please see downstrem evaluations and more details in the paper[(MUDDFormer: Breaking Residual Bottlenecks in Transformers via Multiway Dynamic Dense Connections)](https://arxiv.org/abs/2502.12170). In addition, we open-source Jax training code on [(Github)](https://github.com/Caiyun-AI/MUDDFormer/).
|
| 14 |
+
|
| 15 |
+
We recommend <strong>compiled version</strong> of MUDDPythia with *torch.compile* for inference acceleration. Please refer to Generation section for compile implementation.
|
| 16 |
+
|
| 17 |
+
# Usage
|
| 18 |
+
|
| 19 |
+
## Env
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
pip install transformers==4.40.2 torch==2.5.1 einops==0.8.0
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
## Generation
|
| 26 |
+
|
| 27 |
+
```
|
| 28 |
+
import time
|
| 29 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 30 |
+
import torch
|
| 31 |
+
|
| 32 |
+
import os
|
| 33 |
+
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
|
| 34 |
+
|
| 35 |
+
device = torch.device('cuda:0')
|
| 36 |
+
dtype = torch.bfloat16
|
| 37 |
+
MAX_BATCH_SIZE = 1
|
| 38 |
+
MAX_SEQ_LENGTH = 2048
|
| 39 |
+
NUM_TOKENS_TO_GENERATE = 10
|
| 40 |
+
COMPILE = True
|
| 41 |
+
OPTIMIZED_COMPILE = False
|
| 42 |
+
|
| 43 |
+
if OPTIMIZED_COMPILE:
|
| 44 |
+
import torch._dynamo.config
|
| 45 |
+
import torch._inductor.config
|
| 46 |
+
torch._dynamo.config.cache_size_limit = 64
|
| 47 |
+
torch._inductor.config.coordinate_descent_tuning = True
|
| 48 |
+
torch._inductor.config.triton.unique_kernel_names = True
|
| 49 |
+
torch._inductor.config.fx_graph_cache = True
|
| 50 |
+
|
| 51 |
+
tokenizer = AutoTokenizer.from_pretrained("Caiyun-AI/MUDDPythia-1.4B")
|
| 52 |
+
model = AutoModelForCausalLM.from_pretrained("Caiyun-AI/MUDDPythia-1.4B", trust_remote_code=True)
|
| 53 |
+
|
| 54 |
+
_ = model.to(device=device,dtype=dtype)
|
| 55 |
+
with torch.device(device):
|
| 56 |
+
model.setup_caches(max_batch_size=MAX_BATCH_SIZE, max_seq_length=MAX_SEQ_LENGTH,dtype=dtype)
|
| 57 |
+
|
| 58 |
+
def decode_one_token(model, cur_token, input_pos):
|
| 59 |
+
logits = model(cur_token, input_pos=input_pos, return_tensor=True)
|
| 60 |
+
new_token = torch.argmax(logits[:, -1], dim=-1)[:,None]
|
| 61 |
+
return new_token
|
| 62 |
+
|
| 63 |
+
prompt = "Beijing is the capital of China. London is the capital of"
|
| 64 |
+
input_ids = tokenizer.encode(prompt, return_tensors='pt')
|
| 65 |
+
|
| 66 |
+
compiled_decode_one_token = torch.compile(decode_one_token,mode="reduce-overhead", fullgraph=True) if COMPILE else None
|
| 67 |
+
|
| 68 |
+
print('Start generating tokens, but it will take a few minutes to compile at the first time.')
|
| 69 |
+
for i in range(10):
|
| 70 |
+
t0 = time.time()
|
| 71 |
+
with torch.no_grad():
|
| 72 |
+
generated_ids = model.generate(input_ids.to(device),num_tokens_to_generate=NUM_TOKENS_TO_GENERATE, compiled_decode_one_token=compiled_decode_one_token)
|
| 73 |
+
text = tokenizer.decode(generated_ids[0])
|
| 74 |
+
if i ==0:
|
| 75 |
+
print(f'Generated text: {text}')
|
| 76 |
+
t1 = time.time()
|
| 77 |
+
print(f'Time consumed at iteration {i}: {t1-t0}s\')
|
| 78 |
+
```
|