Downloads · 30 days
184
34% of all-time downloads
Caiyun-AI/DCPythia-6.9B
DCPythia-6.9B is a text generation model from Caiyun-AI. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
DCPythia-6.9B is a pretrained language model on the Pile with 300B tokens. With comparison of Pythia-6.9B, we validate the scaling performance of Dynamically Composable Multi-Head Attention(DCMHA), a parameter and com…
Downloads · 30 days
184
34% of all-time downloads
All-time downloads
540
Public
Repo size
29.6 GB
Likes
1
Public
Click a slice to open those files.
.bin14.8 GB · 100%
From the Hugging Face model README
DCPythia-6.9B is a pretrained language model on the Pile with 300B tokens. With comparison of Pythia-6.9B, we validate the scaling performance of Dynamically Composable Multi-Head Attention(DCMHA), a parameter and computation efficient attention architecture that tackles the shortcomings of MHA and increases the expressive power of the model by dynamically composing attention heads. Please see downstrem evaluations and more details in the paper(Improving Transformers with Dynamically Composable Multi-Head Attention). In addition, we open-source Jax training code on (Github).
We recommend <strong>compiled version</strong> of DCPythia with torch.compile for inference acceleration. Please refer to Generation section for compile implementation.
You need to upgrade transformers to avoid (loading problems).
pip install transformers>=4.40.2
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import os
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
tokenizer = AutoTokenizer.from_pretrained("Caiyun-AI/DCPythia-6.9B")
model = AutoModelForCausalLM.from_pretrained("Caiyun-AI/DCPythia-6.9B", trust_remote_code=True)
device = torch.device('cuda')
MAX_BATCH_SIZE = 1
MAX_SEQ_LENGTH = 2048
NUM_TOKENS_TO_GENERATE = 100
COMPILE = True
_ = model.to(device=device,dtype=torch.float16)
with torch.device(device):
model.setup_caches(max_batch_size=MAX_BATCH_SIZE, max_seq_length=MAX_SEQ_LENGTH, set_kv_cache=True)
def decode_one_token(model, cur_token, input_pos):
logits = model(cur_token, input_pos=input_pos, return_tensor=True)
new_token = torch.argmax(logits[:, -1], dim=-1)[:,None]
return new_token
prompt = "Beijing is the capital of China. London is the capital of"
input_ids = tokenizer.encode(prompt, return_tensors='pt')
compiled_decode_one_token = torch.compile(decode_one_token,mode="reduce-overhead", fullgraph=True) if COMPILE else None
with torch.no_grad():
generated_ids = model.generate(input_ids.to(device),num_tokens_to_generate=NUM_TOKENS_TO_GENERATE, compiled_decode_one_token=compiled_decode_one_token)
text = tokenizer.decode(generated_ids[0])
print('generated text:', text)