Instructions to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("unsloth/cogito-v2-preview-llama-109B-MoE-GGUF", dtype="auto") - llama-cpp-python
How to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="unsloth/cogito-v2-preview-llama-109B-MoE-GGUF", filename="BF16/cogito-v2-preview-llama-109B-MoE-BF16-00001-of-00005.gguf", )
llm.create_chat_completion( messages = "No input example has been defined for this model task." )
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL # Run inference directly in the terminal: llama cli -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL # Run inference directly in the terminal: llama cli -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL # Run inference directly in the terminal: ./llama-cli -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL # Run inference directly in the terminal: ./build/bin/llama-cli -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
Use Docker
docker model run hf.co/unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
- LM Studio
- Jan
- Ollama
How to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with Ollama:
ollama run hf.co/unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
- Unsloth Studio
How to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/cogito-v2-preview-llama-109B-MoE-GGUF to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/cogito-v2-preview-llama-109B-MoE-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/cogito-v2-preview-llama-109B-MoE-GGUF to start chatting
- Pi
How to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
Run Hermes
hermes
- Atomic Chat new
- Docker Model Runner
How to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with Docker Model Runner:
docker model run hf.co/unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
- Lemonade
How to use unsloth/cogito-v2-preview-llama-109B-MoE-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull unsloth/cogito-v2-preview-llama-109B-MoE-GGUF:UD-Q4_K_XL
Run and chat with the model
lemonade run user.cogito-v2-preview-llama-109B-MoE-GGUF-UD-Q4_K_XL
List all available models
lemonade list
| tags: | |
| - unsloth | |
| license: llama4 | |
| library_name: transformers | |
| base_model: | |
| - deepcogito/cogito-v2-preview-llama-109B-MoE | |
| > [!NOTE] | |
| > Includes Unsloth **chat template fixes**! <br> For `llama.cpp`, use `--jinja` | |
| > | |
| <div> | |
| <p style="margin-top: 0;margin-bottom: 0;"> | |
| <em><a href="https://docs.unsloth.ai/basics/unsloth-dynamic-v2.0-gguf">Unsloth Dynamic 2.0</a> achieves superior accuracy & outperforms other leading quants.</em> | |
| </p> | |
| <div style="display: flex; gap: 5px; align-items: center; "> | |
| <a href="https://github.com/unslothai/unsloth/"> | |
| <img src="https://github.com/unslothai/unsloth/raw/main/images/unsloth%20new%20logo.png" width="133"> | |
| </a> | |
| <a href="https://discord.gg/unsloth"> | |
| <img src="https://github.com/unslothai/unsloth/raw/main/images/Discord%20button.png" width="173"> | |
| </a> | |
| <a href="https://docs.unsloth.ai/"> | |
| <img src="https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/documentation%20green%20button.png" width="143"> | |
| </a> | |
| </div> | |
| </div> | |
| <p align="center"> | |
| <img src="images/deep-cogito-logo.png" alt="Logo" width="40%"> | |
| </p> | |
| # Cogito v2 preview - 109B MoE | |
| [Blog Post](https://www.deepcogito.com/research/cogito-v2-preview) | |
| The Cogito v2 LLMs are instruction tuned generative models. All models are released under an open license for commercial use. | |
| - Cogito v2 models are hybrid reasoning models. Each model can answer directly (standard LLM), or self-reflect before answering (like reasoning models). | |
| - The LLMs are trained using **Iterated Distillation and Amplification (IDA)** - an scalable and efficient alignment strategy for superintelligence using iterative self-improvement. | |
| - The models have been optimized for coding, STEM, instruction following and general helpfulness, and have significantly higher multilingual, coding and tool calling capabilities than size equivalent counterparts. | |
| - In both standard and reasoning modes, Cogito v2-preview models outperform their size equivalent counterparts on common industry benchmarks. | |
| - This model is trained in over 30 languages and supports long contexts (upto 10M tokens). | |
| # Evaluations | |
| For detailed evaluations, please refer to the [Blog Post](https://www.deepcogito.com/research/cogito-v2-preview). | |
| # Usage | |
| Here is a snippet below for usage with Transformers: | |
| ```python | |
| import transformers | |
| import torch | |
| model_id = "deepcogito/cogito-v2-preview-llama-109B-MoE" | |
| pipeline = transformers.pipeline( | |
| "text-generation", | |
| model=model_id, | |
| model_kwargs={"torch_dtype": torch.bfloat16}, | |
| device_map="auto", | |
| ) | |
| messages = [ | |
| {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"}, | |
| {"role": "user", "content": "Give me a short introduction to LLMs."}, | |
| ] | |
| outputs = pipeline( | |
| messages, | |
| max_new_tokens=512, | |
| ) | |
| print(outputs[0]["generated_text"][-1]) | |
| ``` | |
| ## Implementing extended thinking | |
| - By default, the model will answer in the standard mode. | |
| - To enable thinking, you can do any one of the two methods: | |
| - Set `enable_thinking=True` while applying the chat template. | |
| - Add a specific system prompt, along with prefilling the response with "\<think\>\n". | |
| **NOTE: Unlike Cogito v1 models, we initiate the response with "\<think\>\n" at the beginning of every output when reasoning is enabled. This is because hybrid models can be brittle at times (<0.1% of the cases), and adding a "\<think\>\n" ensures that the model does indeed respect thinking.** | |
| ### Method 1 - Set enable_thinking=True in the tokenizer | |
| If you are using Huggingface tokenizers, then you can simply use add the argument `enable_thinking=True` to the tokenization (this option is added to the chat template). | |
| Here is an example - | |
| ```python | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| model_name = "deepcogito/cogito-v2-preview-llama-109B-MoE" | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| torch_dtype="auto", | |
| device_map="auto" | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| prompt = "Give me a short introduction to LLMs." | |
| messages = [ | |
| {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"}, | |
| {"role": "user", "content": prompt} | |
| ] | |
| text = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=False, | |
| add_generation_prompt=True, | |
| enable_thinking=True | |
| ) | |
| model_inputs = tokenizer([text], return_tensors="pt").to(model.device) | |
| generated_ids = model.generate( | |
| **model_inputs, | |
| max_new_tokens=512 | |
| ) | |
| generated_ids = [ | |
| output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids) | |
| ] | |
| response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0] | |
| print(response) | |
| ``` | |
| ### Method 2 - Add a specific system prompt, along with prefilling the response with "\<think\>\n". | |
| To enable thinking using this method, you need to do two parts - | |
| Step 1 - Simply use this in the system prompt `system_instruction = 'Enable deep thinking subroutine.'` | |
| If you already have a system_instruction, then use `system_instruction = 'Enable deep thinking subroutine.' + '\n\n' + system_instruction`. | |
| Step 2 - Prefil the response with the tokens `"<think>\n"`. | |
| Here is an example - | |
| ```python | |
| import transformers | |
| import torch | |
| model_name = "deepcogito/cogito-v2-preview-llama-109B-MoE" | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| torch_dtype="auto", | |
| device_map="auto" | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| # Step 1 - Add deep thinking instruction. | |
| DEEP_THINKING_INSTRUCTION = "Enable deep thinking subroutine." | |
| messages = [ | |
| {"role": "system", "content": DEEP_THINKING_INSTRUCTION}, | |
| {"role": "user", "content": "Write a bash script that takes a matrix represented as a string with format '[1,2],[3,4],[5,6]' and prints the transpose in the same format."}, | |
| ] | |
| text = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=False, | |
| add_generation_prompt=True | |
| ) | |
| # Step 2 - Prefill response with "<think>\n". | |
| text += "<think>\n" | |
| # Now, continue as usual. | |
| model_inputs = tokenizer([text], return_tensors="pt").to(model.device) | |
| generated_ids = model.generate( | |
| **model_inputs, | |
| max_new_tokens=512 | |
| ) | |
| generated_ids = [ | |
| output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids) | |
| ] | |
| response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0] | |
| print(response) | |
| ``` | |
| Similarly, if you have a system prompt, you can append the `DEEP_THINKING_INSTRUCTION` to the beginning in this way - | |
| ```python | |
| DEEP_THINKING_INSTRUCTION = "Enable deep thinking subroutine." | |
| system_prompt = "Reply to each prompt with only the actual code - no explanations." | |
| prompt = "Write a bash script that takes a matrix represented as a string with format '[1,2],[3,4],[5,6]' and prints the transpose in the same format." | |
| messages = [ | |
| {"role": "system", "content": DEEP_THINKING_INSTRUCTION + '\n\n' + system_prompt}, | |
| {"role": "user", "content": prompt} | |
| ] | |
| ``` | |
| # Tool Calling | |
| Cogito models support tool calling (single, parallel, multiple and parallel_multiple) both in standard and extended thinking mode. | |
| Here is a snippet - | |
| ```python | |
| # First, define a tool | |
| def get_current_temperature(location: str) -> float: | |
| """ | |
| Get the current temperature at a location. | |
| Args: | |
| location: The location to get the temperature for, in the format "City, Country" | |
| Returns: | |
| The current temperature at the specified location in the specified units, as a float. | |
| """ | |
| return 22. # A real function should probably actually get the temperature! | |
| # Next, create a chat and apply the chat template | |
| messages = [ | |
| {"role": "user", "content": "Hey, what's the temperature in Paris right now?"} | |
| ] | |
| model_inputs = tokenizer.apply_chat_template(messages, tools=[get_current_temperature], add_generation_prompt=True) | |
| text = tokenizer.apply_chat_template(messages, tools=[get_current_temperature], add_generation_prompt=True, tokenize=False) | |
| inputs = tokenizer(text, return_tensors="pt", add_special_tokens=False).to(model.device) | |
| outputs = model.generate(**inputs, max_new_tokens=512) | |
| output_text = tokenizer.batch_decode(outputs)[0][len(text):] | |
| print(output_text) | |
| ``` | |
| This will result in the output - | |
| ``` | |
| <tool_call> | |
| {"name": "get_current_temperature", "arguments": {"location": "Paris, France"}} | |
| </tool_call><|eot|> | |
| ``` | |
| You can then generate text from this input as normal. If the model generates a tool call, you should add it to the chat like so: | |
| ```python | |
| tool_call = {"name": "get_current_temperature", "arguments": {"location": "Paris, France"}} | |
| messages.append({"role": "assistant", "tool_calls": [{"type": "function", "function": tool_call}]}) | |
| ``` | |
| and then call the tool and append the result, with the `tool` role, like so: | |
| ```python | |
| messages.append({"role": "tool", "name": "get_current_temperature", "content": "22.0"}) | |
| ``` | |
| After that, you can `generate()` again to let the model use the tool result in the chat: | |
| ```python | |
| text = tokenizer.apply_chat_template(messages, tools=[get_current_temperature], add_generation_prompt=True, tokenize=False) | |
| inputs = tokenizer(text, return_tensors="pt", add_special_tokens=False).to(model.device) | |
| outputs = model.generate(**inputs, max_new_tokens=512) | |
| output_text = tokenizer.batch_decode(outputs)[0][len(text):] | |
| ``` | |
| This should result in the string - | |
| ``` | |
| 'The current temperature in Paris is 22.0 degrees.<|eot|>' | |
| ``` | |
| ## License | |
| This repository and the model weights are licensed under the [Llama 4 Community License Agreement](https://github.com/meta-llama/llama-models/blob/main/models/llama4/LICENSE) (Llama models' default license agreement). | |
| ## Contact | |
| If you would like to reach out to our team, send an email to [contact@deepcogito.com](contact@deepcogito.com). |