Views
No views yet

1export FRIENDLI_PAT="YOUR PAT"
2docker login registry.friendli.ai -u $YOUR_EMAIL -p $FRIENDLI_PATdocker pull registry.friendli.ai/trial1docker run \
2 --gpus '"device=0,1,2,3"' \
3 -p 8000:8000 \
4 -v ~/.cache/huggingface:/root/.cache/huggingface \
5 -e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \
6 registry.friendli.ai/trial \
7 --web-server-port 8000 \
8 --hf-model-name FriendliAI/Mixtral-8x22B-Instruct-v0.1-fp8 \
9 --num-devices 4 # Use tensor parallelism degree 41export POLICY_DIR=$PWD/policy
2
3mkdir -p $POLICY_DIR
4
5docker run \
6 --gpus '"device=0,1,2,3"' \
7 -p 8000:8000 \
8 -v ~/.cache/huggingface:/root/.cache/huggingface \
9 -v $POLICY_DIR:/policy \
10 -e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \
11 registry.friendli.ai/trial \
12 --web-server-port 8000 \
13 --hf-model-name FriendliAI/Mixtral-8x22B-Instruct-v0.1-fp8 \
14 --num-devices 4 # Use tensor parallelism degree 4 \
15 --algo-policy-dir /policy \
16 --search-policy true$POLICY_DIR.
Now you can create an inference endpoint with this optimal policy as follows:1docker run \
2 --gpus '"device=0,1,2,3"' \
3 -p 8000:8000 \
4 -v ~/.cache/huggingface:/root/.cache/huggingface \
5 -v $POLICY_DIR:/policy \
6 -e FRIENDLI_CONTAINER_SECRET="YOUR CONTAINER SECRET" \
7 registry.friendli.ai/trial \
8 --web-server-port 8000 \
9 --hf-model-name FriendliAI/Mixtral-8x22B-Instruct-v0.1-fp8 \
10 --num-devices 4 # Use tensor parallelism degree 4 \
11 --algo-policy-dir /policy1from transformers import AutoModelForCausalLM
2from mistral_common.protocol.instruct.messages import (
3 AssistantMessage,
4 UserMessage,
5)
6from mistral_common.protocol.instruct.tool_calls import (
7 Tool,
8 Function,
9)
10from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
11from mistral_common.tokens.instruct.normalize import ChatCompletionRequest
12
13device = "cuda" # the device to load the model onto
14
15tokenizer_v3 = MistralTokenizer.v3()
16
17mistral_query = ChatCompletionRequest(
18 tools=[
19 Tool(
20 function=Function(
21 name="get_current_weather",
22 description="Get the current weather",
23 parameters={
24 "type": "object",
25 "properties": {
26 "location": {
27 "type": "string",
28 "description": "The city and state, e.g. San Francisco, CA",
29 },
30 "format": {
31 "type": "string",
32 "enum": ["celsius", "fahrenheit"],
33 "description": "The temperature unit to use. Infer this from the users location.",
34 },
35 },
36 "required": ["location", "format"],
37 },
38 )
39 )
40 ],
41 messages=[
42 UserMessage(content="What's the weather like today in Paris"),
43 ],
44 model="test",
45)
46
47encodeds = tokenizer_v3.encode_chat_completion(mistral_query).tokens
48model = AutoModelForCausalLM.from_pretrained("mistralai/Mixtral-8x22B-Instruct-v0.1")
49model_inputs = encodeds.to(device)
50model.to(device)
51
52generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
53sp_tokenizer = tokenizer_v3.instruct_tokenizer.tokenizer
54decoded = sp_tokenizer.decode(generated_ids[0])
55print(decoded)pip install transformers==4.39.01from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_id = "mistralai/Mixtral-8x22B-Instruct-v0.1"
4tokenizer = AutoTokenizer.from_pretrained(model_id)
5conversation=[
6 {"role": "user", "content": "What's the weather like in Paris?"},
7 {
8 "role": "tool_calls",
9 "content": [
10 {
11 "name": "get_current_weather",
12 "arguments": {"location": "Paris, France", "format": "celsius"},
13
14 }
15 ]
16 },
17 {
18 "role": "tool_results",
19 "content": {"content": 22}
20 },
21 {"role": "assistant", "content": "The current temperature in Paris, France is 22 degrees Celsius."},
22 {"role": "user", "content": "What about San Francisco?"}
23]
24
25
26tools = [{"type": "function", "function": {"name":"get_current_weather", "description": "Get▁the▁current▁weather", "parameters": {"type": "object", "properties": {"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}, "format": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "The temperature unit to use. Infer this from the users location."}},"required":["location","format"]}}}]
27
28# render the tool use prompt as a string:
29tool_use_prompt = tokenizer.apply_chat_template(
30 conversation,
31 chat_template="tool_use",
32 tools=tools,
33 tokenize=False,
34 add_generation_prompt=True,
35
36)
37model = AutoModelForCausalLM.from_pretrained("mistralai/Mixtral-8x22B-Instruct-v0.1")
38
39inputs = tokenizer(tool_use_prompt, return_tensors="pt")
40
41outputs = model.generate(**inputs, max_new_tokens=20)
42print(tokenizer.decode(outputs[0], skip_special_tokens=True))pip install mistral-common1from mistral_common.protocol.instruct.messages import (
2 AssistantMessage,
3 UserMessage,
4)
5from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
6from mistral_common.tokens.instruct.normalize import ChatCompletionRequest
7
8from transformers import AutoTokenizer
9
10tokenizer_v3 = MistralTokenizer.v3()
11
12mistral_query = ChatCompletionRequest(
13 messages=[
14 UserMessage(content="How many experts ?"),
15 AssistantMessage(content="8"),
16 UserMessage(content="How big ?"),
17 AssistantMessage(content="22B"),
18 UserMessage(content="Noice 🎉 !"),
19 ],
20 model="test",
21)
22hf_messages = mistral_query.model_dump()['messages']
23
24tokenized_mistral = tokenizer_v3.encode_chat_completion(mistral_query).tokens
25
26tokenizer_hf = AutoTokenizer.from_pretrained('mistralai/Mixtral-8x22B-Instruct-v0.1')
27tokenized_hf = tokenizer_hf.apply_chat_template(hf_messages, tokenize=True)
28
29assert tokenized_hf == tokenized_mistral