Text Generation
Transformers
Safetensors
English
mistral
human feedback
rlhf
preferences
alignment
HALO
halos
dpo
rl
conversational
text-generation-inference
Instructions to use ContextualAI/Contextual_KTO_Mistral_PairRM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ContextualAI/Contextual_KTO_Mistral_PairRM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ContextualAI/Contextual_KTO_Mistral_PairRM") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ContextualAI/Contextual_KTO_Mistral_PairRM") model = AutoModelForCausalLM.from_pretrained("ContextualAI/Contextual_KTO_Mistral_PairRM", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ContextualAI/Contextual_KTO_Mistral_PairRM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ContextualAI/Contextual_KTO_Mistral_PairRM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ContextualAI/Contextual_KTO_Mistral_PairRM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ContextualAI/Contextual_KTO_Mistral_PairRM
- SGLang
How to use ContextualAI/Contextual_KTO_Mistral_PairRM 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 "ContextualAI/Contextual_KTO_Mistral_PairRM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ContextualAI/Contextual_KTO_Mistral_PairRM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "ContextualAI/Contextual_KTO_Mistral_PairRM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ContextualAI/Contextual_KTO_Mistral_PairRM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ContextualAI/Contextual_KTO_Mistral_PairRM with Docker Model Runner:
docker model run hf.co/ContextualAI/Contextual_KTO_Mistral_PairRM
Fix tokenizer chat template
Browse files- special_tokens_map.json +1 -1
- tokenizer_config.json +10 -3
special_tokens_map.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
| 14 |
"single_word": false
|
| 15 |
},
|
| 16 |
"pad_token": {
|
| 17 |
-
"content": "<
|
| 18 |
"lstrip": false,
|
| 19 |
"normalized": false,
|
| 20 |
"rstrip": false,
|
|
|
|
| 14 |
"single_word": false
|
| 15 |
},
|
| 16 |
"pad_token": {
|
| 17 |
+
"content": "<s>",
|
| 18 |
"lstrip": false,
|
| 19 |
"normalized": false,
|
| 20 |
"rstrip": false,
|
tokenizer_config.json
CHANGED
|
@@ -29,15 +29,22 @@
|
|
| 29 |
},
|
| 30 |
"additional_special_tokens": [],
|
| 31 |
"bos_token": "<s>",
|
| 32 |
-
"chat_template": "{
|
| 33 |
"clean_up_tokenization_spaces": false,
|
| 34 |
"eos_token": "</s>",
|
| 35 |
"legacy": true,
|
|
|
|
| 36 |
"model_max_length": 1000000000000000019884624838656,
|
| 37 |
-
"
|
|
|
|
|
|
|
|
|
|
| 38 |
"sp_model_kwargs": {},
|
| 39 |
"spaces_between_special_tokens": false,
|
|
|
|
| 40 |
"tokenizer_class": "LlamaTokenizer",
|
|
|
|
|
|
|
| 41 |
"unk_token": "<unk>",
|
| 42 |
-
"use_default_system_prompt":
|
| 43 |
}
|
|
|
|
| 29 |
},
|
| 30 |
"additional_special_tokens": [],
|
| 31 |
"bos_token": "<s>",
|
| 32 |
+
"chat_template": "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{% if message['role'] == 'user' %}{{ bos_token + '\n<|user|>\n' + message['content'] + '\n' }}{% elif message['role'] == 'assistant' %}{{ '<|assistant|>\n' + message['content'] + eos_token }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% endif %}",
|
| 33 |
"clean_up_tokenization_spaces": false,
|
| 34 |
"eos_token": "</s>",
|
| 35 |
"legacy": true,
|
| 36 |
+
"max_length": 2048,
|
| 37 |
"model_max_length": 1000000000000000019884624838656,
|
| 38 |
+
"pad_to_multiple_of": null,
|
| 39 |
+
"pad_token": "<s>",
|
| 40 |
+
"pad_token_type_id": 0,
|
| 41 |
+
"padding_side": "right",
|
| 42 |
"sp_model_kwargs": {},
|
| 43 |
"spaces_between_special_tokens": false,
|
| 44 |
+
"stride": 0,
|
| 45 |
"tokenizer_class": "LlamaTokenizer",
|
| 46 |
+
"truncation_side": "right",
|
| 47 |
+
"truncation_strategy": "longest_first",
|
| 48 |
"unk_token": "<unk>",
|
| 49 |
+
"use_default_system_prompt": true
|
| 50 |
}
|