Views
No views yet
text-generation-webuihuggingface-hub Python library:pip3 install huggingface-hubhuggingface-cli download LiteLLMs/Mixtral-8x22B-Instruct-v0.1-GGUF Q4_0/Q4_0-00001-of-00009.gguf --local-dir . --local-dir-use-symlinks Falsehuggingface-cli download LiteLLMs/Mixtral-8x22B-Instruct-v0.1-GGUF --local-dir . --local-dir-use-symlinks False --include='*Q4_K*gguf'huggingface-cli, please see: HF -> Hub Python Library -> Download files -> Download from the CLI.hf_transfer:pip3 install huggingface_hub[hf_transfer]HF_HUB_ENABLE_HF_TRANSFER to 1:HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download LiteLLMs/Mixtral-8x22B-Instruct-v0.1-GGUF Q4_0/Q4_0-00001-of-00009.gguf --local-dir . --local-dir-use-symlinks Falseset HF_HUB_ENABLE_HF_TRANSFER=1 before the download command.llama.cpp from commit d0cee0d or later../main -ngl 35 -m Q4_0/Q4_0-00001-of-00009.gguf --color -c 8192 --temp 0.7 --repeat_penalty 1.1 -n -1 -p "<PROMPT>"-ngl 32 to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.-c 8192 to the desired sequence length. For extended sequence models - eg 8K, 16K, 32K - the necessary RoPE scaling parameters are read from the GGUF file and set by llama.cpp automatically. Note that longer sequence lengths require much more resources, so you may need to reduce this value.-p <PROMPT> argument with -i -instext-generation-webui1# Base ctransformers with no GPU acceleration
2pip install llama-cpp-python
3# With NVidia CUDA acceleration
4CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python
5# Or with OpenBLAS acceleration
6CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
7# Or with CLBLast acceleration
8CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python
9# Or with AMD ROCm GPU acceleration (Linux only)
10CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
11# Or with Metal GPU acceleration for macOS systems only
12CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
13# In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:
14$env:CMAKE_ARGS = "-DLLAMA_OPENBLAS=on"
15pip install llama-cpp-python1from llama_cpp import Llama
2# Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
3llm = Llama(
4 model_path="./Q4_0/Q4_0-00001-of-00009.gguf", # Download the model file first
5 n_ctx=32768, # The max sequence length to use - note that longer sequence lengths require much more resources
6 n_threads=8, # The number of CPU threads to use, tailor to your system and the resulting performance
7 n_gpu_layers=35 # The number of layers to offload to GPU, if you have GPU acceleration available
8)
9# Simple inference example
10output = llm(
11 "<PROMPT>", # Prompt
12 max_tokens=512, # Generate up to 512 tokens
13 stop=["</s>"], # Example stop token - not necessarily correct for this specific model! Please check before using.
14 echo=True # Whether to echo the prompt
15)
16# Chat Completion API
17llm = Llama(model_path="./Q4_0/Q4_0-00001-of-00009.gguf", chat_format="llama-2") # Set chat_format according to the model you are using
18llm.create_chat_completion(
19 messages = [
20 {"role": "system", "content": "You are a story writing assistant."},
21 {
22 "role": "user",
23 "content": "Write a story about llamas."
24 }
25 ]
26)1from 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