Instructions to use Linly-AI/Chinese-LLaMA-2-7B-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Linly-AI/Chinese-LLaMA-2-7B-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Linly-AI/Chinese-LLaMA-2-7B-hf")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Linly-AI/Chinese-LLaMA-2-7B-hf") model = AutoModelForCausalLM.from_pretrained("Linly-AI/Chinese-LLaMA-2-7B-hf") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Linly-AI/Chinese-LLaMA-2-7B-hf with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Linly-AI/Chinese-LLaMA-2-7B-hf" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Linly-AI/Chinese-LLaMA-2-7B-hf", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Linly-AI/Chinese-LLaMA-2-7B-hf
- SGLang
How to use Linly-AI/Chinese-LLaMA-2-7B-hf 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 "Linly-AI/Chinese-LLaMA-2-7B-hf" \ --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": "Linly-AI/Chinese-LLaMA-2-7B-hf", "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 "Linly-AI/Chinese-LLaMA-2-7B-hf" \ --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": "Linly-AI/Chinese-LLaMA-2-7B-hf", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Linly-AI/Chinese-LLaMA-2-7B-hf with Docker Model Runner:
docker model run hf.co/Linly-AI/Chinese-LLaMA-2-7B-hf
tokenizer config好像有些问题
#2
by Skepsun - opened
{"bos_token": "", "eos_token": "", "model_max_length": 1000000000000000019884624838656, "tokenizer_class": "LlamaTokenizer", "unk_token": ""}
这会不会影响模型的后续训练和使用
推理可以参考 https://huggingface.co/spaces/Linly-AI/Linly-ChatFlow/blob/main/app.py
import os
os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
import torch
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
def init_model():
model = AutoModelForCausalLM.from_pretrained("Linly-AI/Chinese-LLaMA-2-7B-hf", device_map="cuda:0", torch_dtype=torch.float16, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("Linly-AI/Chinese-LLaMA-2-7B-hf", use_fast=False, trust_remote_code=True)
return model, tokenizer
def chat(prompt, top_k, temperature):
prompt = f"### Instruction:{prompt.strip()} ### Response:"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda:0")
generate_ids = model.generate(inputs.input_ids, do_sample=True, max_new_tokens=2048, top_k=int(top_k), top_p=0.84, temperature=float(temperature), repetition_penalty=1.15, eos_token_id=2, bos_token_id=1, pad_token_id=0)
response = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
response = response.lstrip(prompt)
print('-log: ',prompt, response)
return response
if __name__ == '__main__':
model, tokenizer = init_model()
demo = gr.Interface(
fn=chat,
inputs=["text", gr.Slider(1, 60, value=10, step=1), gr.Slider(0.1, 2.0, value=1.0, step=0.1)],
outputs="text",
)
demo.launch()
建议还是更新一下文件,如果用第三方库加载(例如vllm),tokenizer文件有问题会影响文本编码。毕竟这根本不费事。
好的