Views
No views yet
text-generation-webuihuggingface-hub Python library:pip3 install huggingface-hubhuggingface-cli download LiteLLMs/Mistral-7B-Instruct-v0.3-GGUF Q4_0/Q4_0-00001-of-00009.gguf --local-dir . --local-dir-use-symlinks Falsehuggingface-cli download LiteLLMs/Mistral-7B-Instruct-v0.3-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/Mistral-7B-Instruct-v0.3-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)mistralai/Mistral-7B-Instruct-v0.3 with mistral-inference. For HF transformers code snippets, please keep scrolling.pip install mistral_inference1from huggingface_hub import snapshot_download
2from pathlib import Path
3
4mistral_models_path = Path.home().joinpath('mistral_models', '7B-Instruct-v0.3')
5mistral_models_path.mkdir(parents=True, exist_ok=True)
6
7snapshot_download(repo_id="mistralai/Mistral-7B-Instruct-v0.3", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)mistral_inference, a mistral-chat CLI command should be available in your environment. You can chat with the model usingmistral-chat $HOME/mistral_models/7B-Instruct-v0.3 --instruct --max_tokens 2561from mistral_inference.model import Transformer
2from mistral_inference.generate import generate
3
4from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
5from mistral_common.protocol.instruct.messages import UserMessage
6from mistral_common.protocol.instruct.request import ChatCompletionRequest
7
8
9tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
10model = Transformer.from_folder(mistral_models_path)
11
12completion_request = ChatCompletionRequest(messages=[UserMessage(content="Explain Machine Learning to me in a nutshell.")])
13
14tokens = tokenizer.encode_chat_completion(completion_request).tokens
15
16out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
17result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
18
19print(result)1from mistral_common.protocol.instruct.tool_calls import Function, Tool
2from mistral_inference.model import Transformer
3from mistral_inference.generate import generate
4
5from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
6from mistral_common.protocol.instruct.messages import UserMessage
7from mistral_common.protocol.instruct.request import ChatCompletionRequest
8
9
10tokenizer = MistralTokenizer.from_file(f"{mistral_models_path}/tokenizer.model.v3")
11model = Transformer.from_folder(mistral_models_path)
12
13completion_request = ChatCompletionRequest(
14 tools=[
15 Tool(
16 function=Function(
17 name="get_current_weather",
18 description="Get the current weather",
19 parameters={
20 "type": "object",
21 "properties": {
22 "location": {
23 "type": "string",
24 "description": "The city and state, e.g. San Francisco, CA",
25 },
26 "format": {
27 "type": "string",
28 "enum": ["celsius", "fahrenheit"],
29 "description": "The temperature unit to use. Infer this from the users location.",
30 },
31 },
32 "required": ["location", "format"],
33 },
34 )
35 )
36 ],
37 messages=[
38 UserMessage(content="What's the weather like today in Paris?"),
39 ],
40)
41
42tokens = tokenizer.encode_chat_completion(completion_request).tokens
43
44out_tokens, _ = generate([tokens], model, max_tokens=64, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
45result = tokenizer.instruct_tokenizer.tokenizer.decode(out_tokens[0])
46
47print(result)transformerstransformers to generate text, you can do something like this.1from transformers import pipeline
2
3messages = [
4 {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
5 {"role": "user", "content": "Who are you?"},
6]
7chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
8chatbot(messages)