Instructions to use wenge-research/yayi-13b-llama2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use wenge-research/yayi-13b-llama2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="wenge-research/yayi-13b-llama2")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("wenge-research/yayi-13b-llama2") model = AutoModelForCausalLM.from_pretrained("wenge-research/yayi-13b-llama2") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use wenge-research/yayi-13b-llama2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "wenge-research/yayi-13b-llama2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "wenge-research/yayi-13b-llama2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/wenge-research/yayi-13b-llama2
- SGLang
How to use wenge-research/yayi-13b-llama2 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 "wenge-research/yayi-13b-llama2" \ --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": "wenge-research/yayi-13b-llama2", "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 "wenge-research/yayi-13b-llama2" \ --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": "wenge-research/yayi-13b-llama2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use wenge-research/yayi-13b-llama2 with Docker Model Runner:
docker model run hf.co/wenge-research/yayi-13b-llama2
้ ๆๅคงๆจกๅ
ไป็ป
้ ๆๅคงๆจกๅๅจ็พไธ็บงไบบๅทฅๆ้ ็้ซ่ดจ้้ขๅๆฐๆฎไธ่ฟ่กๆไปคๅพฎ่ฐๅพๅฐ๏ผ่ฎญ็ปๆฐๆฎ่ฆ็ๅชไฝๅฎฃไผ ใ่ๆ ๅๆใๅ ฌๅ ฑๅฎๅ จใ้่้ฃๆงใๅๅธๆฒป็็ญไบๅคง้ขๅ๏ผไธ็พ็ง่ช็ถ่ฏญ่จๆไปคไปปๅกใ้ ๆๅคงๆจกๅไป้ข่ฎญ็ปๅๅงๅๆ้ๅฐ้ขๅๆจกๅ็่ฟญไปฃ่ฟ็จไธญ๏ผๆไปฌ้ๆญฅๅขๅผบไบๅฎ็ไธญๆๅบ็ก่ฝๅๅ้ขๅๅๆ่ฝๅ๏ผๅนถๅขๅ ไบๅค่ฝฎๅฏน่ฏๅ้จๅๆไปถ่ฝๅใๅๆถ๏ผ็ป่ฟๆฐ็พๅ็จๆทๅ ๆต่ฟ็จไธญๆ็ปญไธๆญ็ไบบๅทฅๅ้ฆไผๅ๏ผๆไปฌ่ฟไธๆญฅๆๅไบๆจกๅๆง่ฝๅๅฎๅ จๆงใ
้่ฟ้ ๆๅคงๆจกๅ็ๅผๆบไธบไฟ่ฟไธญๆ้ข่ฎญ็ปๅคงๆจกๅๅผๆบ็คพๅบ็ๅๅฑ๏ผ่ดก็ฎ่ชๅทฑ็ไธไปฝๅ้๏ผ้่ฟๅผๆบ๏ผไธๆฏไธไฝๅไฝไผไผดๅ ฑๅปบ้ ๆๅคงๆจกๅ็ๆใ
News: ๐ฅ ้ ๆๅคงๆจกๅๅทฒๅผๆบๅบไบ LLaMA 2 ็ไธญๆไผๅๆจกๅ็ๆฌ๏ผๆข็ดข้็จไบไธญๆๅค้ขๅไปปๅก็ๆๆฐๅฎ่ทตใ
ๆจกๅๅฐๅ
| ๆจกๅๅ็งฐ | ๐คHFๆจกๅๆ ่ฏ | ไธ่ฝฝๅฐๅ |
|---|---|---|
| YaYi-7B | wenge-research/yayi-7b | ๆจกๅไธ่ฝฝ |
| YaYi-7B-Llama2 | wenge-research/yayi-7b-llama2 | ๆจกๅไธ่ฝฝ |
| YaYi-13B-Llama2 | wenge-research/yayi-13b-llama2 | ๆจกๅไธ่ฝฝ |
| YaYi-70B-Llama2 | wenge-research/yayi-70b-llama2 | ๆจกๅไธ่ฝฝ |
่ฏฆๆ ่ฏทๅ่ๆไปฌ็ ๐ปGithub Repoใ
่ฟ่กๆนๅผ
import torch
from transformers import LlamaForCausalLM, LlamaTokenizer, GenerationConfig
from transformers import StoppingCriteria, StoppingCriteriaList
pretrained_model_name_or_path = "wenge-research/yayi-13b-llama2"
tokenizer = LlamaTokenizer.from_pretrained(pretrained_model_name_or_path)
model = LlamaForCausalLM.from_pretrained(pretrained_model_name_or_path, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=False)
# Define the stopping criteria
class KeywordsStoppingCriteria(StoppingCriteria):
def __init__(self, keywords_ids:list):
self.keywords = keywords_ids
def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
if input_ids[0][-1] in self.keywords:
return True
return False
stop_words = ["<|End|>", "<|YaYi|>", "<|Human|>", "</s>"]
stop_ids = [tokenizer.encode(w)[-1] for w in stop_words]
stop_criteria = KeywordsStoppingCriteria(stop_ids)
# inference
prompt = "ไฝ ๆฏ่ฐ๏ผ"
formatted_prompt = f"""<|System|>:
You are a helpful, respectful and honest assistant named YaYi developed by Beijing Wenge Technology Co.,Ltd. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
<|Human|>:
{prompt}
<|YaYi|>:
"""
inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
eos_token_id = tokenizer("<|End|>").input_ids[0]
generation_config = GenerationConfig(
eos_token_id=eos_token_id,
pad_token_id=eos_token_id,
do_sample=True,
max_new_tokens=256,
temperature=0.3,
repetition_penalty=1.1,
no_repeat_ngram_size=0
)
response = model.generate(**inputs, generation_config=generation_config, stopping_criteria=StoppingCriteriaList([stop_criteria]))
response = [response[0][len(inputs.input_ids[0]):]]
response_str = tokenizer.batch_decode(response, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
print(response_str)
YaYi
Introduction
YaYi was fine-tuned on millions of artificially constructed high-quality domain data. This training data covers five key domains: media publicity, public opinion analysis, public safety, financial risk control, and urban governance, encompassing over a hundred natural language instruction tasks. Throughout the iterative development process of the YaYi, starting from pre-training initialization weights and progressing to domain-specific model, we have steadily enhanced its foundational Chinese language capabilities and domain analysis capabilities. We've also introduced multi-turn conversation enhancements and integrated various plug-in capabilities. Furthermore, through continuous manual feedback and optimization from hundreds of users during the internal testing phase, we've meticulously refined the model's performance and security.
By open-sourcing the YaYi model, we will contribute our own efforts to the development of the Chinese pre-trained large language model open-source community. Through this open-source initiative, we seek to collaborate with every partner to build the YaYi model ecosystem together.
News: ๐ฅ YaYi has open sourced the Chinese optimization model version based on LLaMA 2 to explore the latest practices suitable for Chinese multi-domain tasks.
Model download
| Model | ๐คHF Model Name | Download Links |
|---|---|---|
| YaYi-7B | wenge-research/yayi-7b | Download |
| YaYi-7B-Llama2 | wenge-research/yayi-7b-llama2 | Download |
| YaYi-13B-Llama2 | wenge-research/yayi-13b-llama2 | Download |
| YaYi-70B-Llama2 | wenge-research/yayi-70b-llama2 | Download |
For more details, please refer to our ๐ปGithub Repoใ
Run
import torch
from transformers import LlamaForCausalLM, LlamaTokenizer, GenerationConfig
from transformers import StoppingCriteria, StoppingCriteriaList
pretrained_model_name_or_path = "wenge-research/yayi-13b-llama2"
tokenizer = LlamaTokenizer.from_pretrained(pretrained_model_name_or_path)
model = LlamaForCausalLM.from_pretrained(pretrained_model_name_or_path, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=False)
# Define the stopping criteria
class KeywordsStoppingCriteria(StoppingCriteria):
def __init__(self, keywords_ids:list):
self.keywords = keywords_ids
def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
if input_ids[0][-1] in self.keywords:
return True
return False
stop_words = ["<|End|>", "<|YaYi|>", "<|Human|>", "</s>"]
stop_ids = [tokenizer.encode(w)[-1] for w in stop_words]
stop_criteria = KeywordsStoppingCriteria(stop_ids)
# inference
prompt = "ไฝ ๆฏ่ฐ๏ผ"
formatted_prompt = f"""<|System|>:
You are a helpful, respectful and honest assistant named YaYi developed by Beijing Wenge Technology Co.,Ltd. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
<|Human|>:
{prompt}
<|YaYi|>:
"""
inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
eos_token_id = tokenizer("<|End|>").input_ids[0]
generation_config = GenerationConfig(
eos_token_id=eos_token_id,
pad_token_id=eos_token_id,
do_sample=True,
max_new_tokens=256,
temperature=0.3,
repetition_penalty=1.1,
no_repeat_ngram_size=0
)
response = model.generate(**inputs, generation_config=generation_config, stopping_criteria=StoppingCriteriaList([stop_criteria]))
response = [response[0][len(inputs.input_ids[0]):]]
response_str = tokenizer.batch_decode(response, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
print(response_str)
- Downloads last month
- 954