HuggingFaceTB/cosmopedia-100k
Viewer • Updated • 100k • 853 • 48
How to use benchang1110/Taiwan-tinyllama-v1.0-base with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="benchang1110/Taiwan-tinyllama-v1.0-base") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("benchang1110/Taiwan-tinyllama-v1.0-base")
model = AutoModelForCausalLM.from_pretrained("benchang1110/Taiwan-tinyllama-v1.0-base")How to use benchang1110/Taiwan-tinyllama-v1.0-base with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "benchang1110/Taiwan-tinyllama-v1.0-base"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "benchang1110/Taiwan-tinyllama-v1.0-base",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/benchang1110/Taiwan-tinyllama-v1.0-base
How to use benchang1110/Taiwan-tinyllama-v1.0-base with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "benchang1110/Taiwan-tinyllama-v1.0-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": "benchang1110/Taiwan-tinyllama-v1.0-base",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "benchang1110/Taiwan-tinyllama-v1.0-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": "benchang1110/Taiwan-tinyllama-v1.0-base",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use benchang1110/Taiwan-tinyllama-v1.0-base with Docker Model Runner:
docker model run hf.co/benchang1110/Taiwan-tinyllama-v1.0-base
This is a continue-pretrained version of Tinyllama tailored for traditional Chinese. The continue-pretraining dataset contains roughly 2B tokens.
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
def generate_response(input):
'''
simple test for the model
'''
# tokenzize the input
tokenized_input = tokenizer.encode_plus(input, return_tensors='pt').to(device)
# generate the response
outputs = model.generate(
input_ids=tokenized_input['input_ids'],
attention_mask=tokenized_input['attention_mask'],
pad_token_id=tokenizer.pad_token_id,
do_sample=False,
repetition_penalty=1.3,
max_length=500
)
# decode the response
return tokenizer.decode(outputs[0], skip_special_tokens=True)
if __name__ == '__main__':
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = AutoModelForCausalLM.from_pretrained("benchang1110/Taiwan-tinyllama-v1.0-base",device_map=device,torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained("benchang1110/Taiwan-tinyllama-v1.0-base")
while(True):
text = input("input a simple prompt:")
print('System:', generate_response(text))
Using bfloat16, the VRAM required is around 3GB!!!