Text Generation
MLX
Safetensors
English
CoDA
quantized
text-diffusion
conversational
4-bit precision
Instructions to use TiGa-RCE/CoDA-v0-Instruct-MLX-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use TiGa-RCE/CoDA-v0-Instruct-MLX-4bit with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("TiGa-RCE/CoDA-v0-Instruct-MLX-4bit") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use TiGa-RCE/CoDA-v0-Instruct-MLX-4bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "TiGa-RCE/CoDA-v0-Instruct-MLX-4bit"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "TiGa-RCE/CoDA-v0-Instruct-MLX-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use TiGa-RCE/CoDA-v0-Instruct-MLX-4bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "TiGa-RCE/CoDA-v0-Instruct-MLX-4bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "TiGa-RCE/CoDA-v0-Instruct-MLX-4bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8080/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TiGa-RCE/CoDA-v0-Instruct-MLX-4bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use TiGa-RCE/CoDA-v0-Instruct-MLX-4bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "TiGa-RCE/CoDA-v0-Instruct-MLX-4bit"
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 TiGa-RCE/CoDA-v0-Instruct-MLX-4bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use TiGa-RCE/CoDA-v0-Instruct-MLX-4bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "TiGa-RCE/CoDA-v0-Instruct-MLX-4bit"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "TiGa-RCE/CoDA-v0-Instruct-MLX-4bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Download attention.py from TiGa-RCE/CoDA-v0-Instruct-MLX-4bit: direct link, hf CLI and curl.
- Browser
- Download file 3.6 kB
-
https://huggingface.co/TiGa-RCE/CoDA-v0-Instruct-MLX-4bit/resolve/main/attention.py
- Command line
-
hf download hf://TiGa-RCE/CoDA-v0-Instruct-MLX-4bit/attention.py
-
curl -L -o attention.py https://huggingface.co/TiGa-RCE/CoDA-v0-Instruct-MLX-4bit/resolve/main/attention.py
3.6 kB
| import math | |
| from typing import Any | |
| import torch | |
| from torch import nn | |
| from torch.nn.functional import scaled_dot_product_attention | |
| from torch.nn.attention import SDPBackend, sdpa_kernel | |
| from .model_config import CoDAConfig | |
| def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor: | |
| """ | |
| This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch, | |
| num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim) | |
| """ | |
| batch, num_key_value_heads, slen, head_dim = hidden_states.shape | |
| if n_rep == 1: | |
| return hidden_states | |
| hidden_states = hidden_states[:, :, None, :, :].expand( | |
| batch, num_key_value_heads, n_rep, slen, head_dim | |
| ) | |
| return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim) | |
| class AttentionModule(nn.Module): | |
| def __init__(self, config: CoDAConfig, kernel_config: dict[str, Any] | None = None): | |
| super().__init__() | |
| self.config = config | |
| self.kernel_config = kernel_config | |
| self.partition_spec = None | |
| def forward( | |
| self, | |
| query_states: torch.Tensor, | |
| key_states: torch.Tensor, | |
| value_states: torch.Tensor, | |
| attention_mask: torch.Tensor | None = None, | |
| ): | |
| """GPU-optimized PyTorch implementation""" | |
| if self.config.attention_kernel != "splash_attention": | |
| num_key_value_groups = ( | |
| self.config.num_attention_heads // self.config.num_key_value_heads | |
| ) | |
| key_states = repeat_kv(key_states, num_key_value_groups) | |
| value_states = repeat_kv(value_states, num_key_value_groups) | |
| bsz, num_heads, q_len, head_dim = query_states.size() | |
| head_dim = value_states.shape[-1] | |
| kv_seq_len = key_states.shape[-2] | |
| # Use SDPA with appropriate backend | |
| match self.config.attention_kernel: | |
| case "splash_attention": | |
| raise NotImplementedError( | |
| "Splash Attention is not supported in GPU environment" | |
| ) | |
| case "flash_attention": | |
| # Try to use flash attention backend, fallback to default if not available | |
| with sdpa_kernel(SDPBackend.FLASH_ATTENTION): | |
| attn_output = scaled_dot_product_attention( | |
| query_states, | |
| key_states, | |
| value_states, | |
| dropout_p=( | |
| self.config.attention_dropout if self.training else 0.0 | |
| ), | |
| is_causal=False, # weiran: causal=False for bi-directional attention | |
| ) | |
| case _: | |
| # Default implementation - use math backend for compatibility | |
| with sdpa_kernel(SDPBackend.MATH): | |
| attn_output = scaled_dot_product_attention( | |
| query_states, | |
| key_states, | |
| value_states, | |
| dropout_p=( | |
| self.config.attention_dropout if self.training else 0.0 | |
| ), | |
| is_causal=False, # weiran: causal=False for bi-directional attention | |
| ) | |
| if attn_output.size() != (bsz, num_heads, q_len, head_dim): | |
| raise ValueError( | |
| f"`attn_output` should be of size {(bsz, num_heads, q_len, head_dim)}, but is" | |
| f" {attn_output.size()}" | |
| ) | |
| return attn_output | |