Text Generation
Transformers
ONNX
Safetensors
Chinese
t5
text2text-generation
text-generation-inference
custom_code
Instructions to use yjk123/ChatLM-mini-Chinese with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yjk123/ChatLM-mini-Chinese with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yjk123/ChatLM-mini-Chinese", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("yjk123/ChatLM-mini-Chinese", trust_remote_code=True) model = AutoModelForSeq2SeqLM.from_pretrained("yjk123/ChatLM-mini-Chinese", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use yjk123/ChatLM-mini-Chinese with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yjk123/ChatLM-mini-Chinese" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yjk123/ChatLM-mini-Chinese", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/yjk123/ChatLM-mini-Chinese
- SGLang
How to use yjk123/ChatLM-mini-Chinese 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 "yjk123/ChatLM-mini-Chinese" \ --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": "yjk123/ChatLM-mini-Chinese", "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 "yjk123/ChatLM-mini-Chinese" \ --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": "yjk123/ChatLM-mini-Chinese", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use yjk123/ChatLM-mini-Chinese with Docker Model Runner:
docker model run hf.co/yjk123/ChatLM-mini-Chinese
| import torch | |
| from torch import Tensor, LongTensor | |
| from transformers import T5ForConditionalGeneration, T5Config | |
| from transformers import TextIteratorStreamer | |
| from transformers.generation.configuration_utils import GenerationConfig | |
| class TextToTextModel(T5ForConditionalGeneration): | |
| def __init__(self, config: T5Config) -> None: | |
| ''' | |
| TextToTextModel继承T5ForConditionalGeneration | |
| ''' | |
| super().__init__(config) | |
| def my_generate(self, | |
| input_ids: LongTensor, | |
| attention_mask: LongTensor, | |
| max_seq_len: int=256, | |
| search_type: str='beam', | |
| streamer: TextIteratorStreamer=None, | |
| ) -> Tensor: | |
| ''' | |
| 自定义gennerate方法方便调用、测试 | |
| search_type: ['greedy', 'beam', 'sampling', 'contrastive', ] | |
| - *greedy decoding* by calling [`~generation.GenerationMixin.greedy_search`] if `num_beams=1` and | |
| `do_sample=False` | |
| - *contrastive search* by calling [`~generation.GenerationMixin.contrastive_search`] if `penalty_alpha>0.` | |
| and `top_k>1` | |
| - *multinomial sampling* by calling [`~generation.GenerationMixin.sample`] if `num_beams=1` and | |
| `do_sample=True` | |
| - *beam-search decoding* by calling [`~generation.GenerationMixin.beam_search`] if `num_beams>1` and | |
| `do_sample=False` | |
| - *beam-search multinomial sampling* by calling [`~generation.GenerationMixin.beam_sample`] if | |
| `num_beams>1` and `do_sample=True` | |
| ''' | |
| generation_config = GenerationConfig() | |
| generation_config.remove_invalid_values = True | |
| generation_config.eos_token_id = 1 | |
| generation_config.pad_token_id = 0 | |
| generation_config.decoder_start_token_id = self.config.decoder_start_token_id | |
| generation_config.max_new_tokens = max_seq_len | |
| # generation_config.repetition_penalty = 1.1 # 重复词惩罚 | |
| if search_type == 'greedy': | |
| generation_config.num_beams = 1 | |
| generation_config.do_sample = False | |
| elif search_type == 'beam': | |
| generation_config.top_k = 50 | |
| generation_config.num_beams = 5 | |
| generation_config.do_sample = True | |
| generation_config.top_p = 0.95 | |
| generation_config.no_repeat_ngram_size = 4 | |
| generation_config.length_penalty = -2.0 | |
| generation_config.early_stopping = True | |
| elif search_type == 'sampling': | |
| generation_config.num_beams = 1 | |
| generation_config.do_sample = True | |
| generation_config.top_k = 50 | |
| generation_config.temperature = 0.98 # 越低概率越趋向于均匀分布 | |
| generation_config.top_p = 0.80 | |
| generation_config.no_repeat_ngram_size = 4 | |
| elif search_type == 'contrastive': | |
| generation_config.penalty_alpha = 0.5 | |
| generation_config.top_k = 50 | |
| result = self.generate( | |
| inputs=input_ids, | |
| attention_mask=attention_mask, | |
| generation_config=generation_config, | |
| streamer=streamer, | |
| ) | |
| return result | |