Text Generation
Transformers
Safetensors
English
jarvis_titan_moe
Mixture of Experts
deepseek-moe
titans-neural-memory
tri-brid-memory
differential-holographic-attention
dha-3
csa3-perturbative-attention
multi-token-prediction
reasoning
math
code
agentic
long-context
conversational
custom_code
Instructions to use dhanesh-hf/Jarvis-Titan-M4-Activated with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dhanesh-hf/Jarvis-Titan-M4-Activated with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="dhanesh-hf/Jarvis-Titan-M4-Activated", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("dhanesh-hf/Jarvis-Titan-M4-Activated", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use dhanesh-hf/Jarvis-Titan-M4-Activated with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "dhanesh-hf/Jarvis-Titan-M4-Activated" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dhanesh-hf/Jarvis-Titan-M4-Activated", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/dhanesh-hf/Jarvis-Titan-M4-Activated
- SGLang
How to use dhanesh-hf/Jarvis-Titan-M4-Activated with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "dhanesh-hf/Jarvis-Titan-M4-Activated" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dhanesh-hf/Jarvis-Titan-M4-Activated", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "dhanesh-hf/Jarvis-Titan-M4-Activated" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dhanesh-hf/Jarvis-Titan-M4-Activated", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use dhanesh-hf/Jarvis-Titan-M4-Activated with Docker Model Runner:
docker model run hf.co/dhanesh-hf/Jarvis-Titan-M4-Activated
File size: 6,352 Bytes
0e449ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | """
J.A.R.V.I.S. TITAN 14.8B MoE — Custom Model Architecture (DeepSeekMoE Style)
Hyper-Optimized with Group-Disjoint Constrained Routing (0.00% Twin Collisions)
"""
import torch
import torch.nn as nn
import torch.nn.functional as F
from transformers.models.qwen2.configuration_qwen2 import Qwen2Config
from transformers.models.qwen2.modeling_qwen2 import (
Qwen2ForCausalLM, Qwen2Model, Qwen2DecoderLayer
)
class JarvisTitanMoEConfig(Qwen2Config):
model_type = "jarvis_titan_moe"
keys_to_ignore_at_loading = ["rotary_emb.inv_freq"]
def __init__(
self,
vocab_size=152064,
hidden_size=3584,
intermediate_size=18944,
num_hidden_layers=28,
num_attention_heads=28,
num_key_value_heads=4,
hidden_act="silu",
max_position_embeddings=32768,
initializer_range=0.02,
rms_norm_eps=1e-6,
use_cache=True,
rope_theta=1000000.0,
rope_scaling=None,
attention_dropout=0.0,
num_routed_experts=8,
num_shared_experts=1,
num_experts_per_tok=2,
expert_intermediate_size=4736,
routed_scaling_factor=1.5,
group_disjoint_routing=True,
**kwargs
):
self.num_routed_experts = num_routed_experts
self.num_shared_experts = num_shared_experts
self.num_experts_per_tok = num_experts_per_tok
self.expert_intermediate_size = expert_intermediate_size
self.routed_scaling_factor = routed_scaling_factor
self.group_disjoint_routing = group_disjoint_routing
super().__init__(
vocab_size=vocab_size,
hidden_size=hidden_size,
intermediate_size=intermediate_size,
num_hidden_layers=num_hidden_layers,
num_attention_heads=num_attention_heads,
num_key_value_heads=num_key_value_heads,
hidden_act=hidden_act,
max_position_embeddings=max_position_embeddings,
initializer_range=initializer_range,
rms_norm_eps=rms_norm_eps,
use_cache=use_cache,
rope_theta=rope_theta,
rope_scaling=rope_scaling,
attention_dropout=attention_dropout,
**kwargs
)
class DeepSeekMoEMLP(nn.Module):
def __init__(self, config: JarvisTitanMoEConfig):
super().__init__()
self.hidden_size = config.hidden_size
self.expert_size = config.expert_intermediate_size
self.num_routed = config.num_routed_experts
self.top_k = config.num_experts_per_tok
self.act_fn = nn.SiLU()
self.group_disjoint = getattr(config, "group_disjoint_routing", True)
# 1. Shared Expert
self.shared_gate = nn.Linear(self.hidden_size, self.expert_size * config.num_shared_experts, bias=False)
self.shared_up = nn.Linear(self.hidden_size, self.expert_size * config.num_shared_experts, bias=False)
self.shared_down = nn.Linear(self.expert_size * config.num_shared_experts, self.hidden_size, bias=False)
# 2. Routed Experts
self.routed_gate = nn.Parameter(torch.empty(self.num_routed, self.expert_size, self.hidden_size))
self.routed_up = nn.Parameter(torch.empty(self.num_routed, self.expert_size, self.hidden_size))
self.routed_down = nn.Parameter(torch.empty(self.num_routed, self.hidden_size, self.expert_size))
# 3. Router Gate
self.router = nn.Linear(self.hidden_size, self.num_routed, bias=False)
def forward(self, x):
batch_size, seq_len, hidden_dim = x.shape
x_flat = x.view(-1, hidden_dim)
# Shared Expert forward
shared_out = self.shared_down(self.act_fn(self.shared_gate(x_flat)) * self.shared_up(x_flat))
# Router Logits
router_logits = self.router(x_flat)
routing_weights = F.softmax(router_logits, dim=-1)
if self.group_disjoint:
# Group-Disjoint Constrained Selection (0.00% Twin Collisions!)
e1 = torch.argmax(routing_weights, dim=-1) # [N]
p1 = torch.gather(routing_weights, 1, e1.unsqueeze(1))
masked = routing_weights.clone()
for b in range(x_flat.shape[0]):
grp = e1[b].item() % 3
for e in range(self.num_routed):
if e % 3 == grp:
masked[b, e] = -1.0 # Mask out all twin copies in the same chunk group
e2 = torch.argmax(masked, dim=-1)
p2 = torch.gather(routing_weights, 1, e2.unsqueeze(1))
topk_indices = torch.stack([e1, e2], dim=-1)
topk_weights = torch.cat([p1, p2], dim=-1)
topk_weights = topk_weights / topk_weights.sum(dim=-1, keepdim=True)
else:
topk_weights, topk_indices = torch.topk(routing_weights, self.top_k, dim=-1)
topk_weights = topk_weights / topk_weights.sum(dim=-1, keepdim=True)
routed_out = torch.zeros_like(x_flat)
for k in range(self.top_k):
expert_idx = topk_indices[:, k]
weight = topk_weights[:, k].unsqueeze(-1)
for e in range(self.num_routed):
mask = (expert_idx == e)
if mask.any():
tokens = x_flat[mask]
h = self.act_fn(F.linear(tokens, self.routed_gate[e])) * F.linear(tokens, self.routed_up[e])
out = F.linear(h, self.routed_down[e])
routed_out[mask] += weight[mask] * out
return (shared_out + routed_out).view(batch_size, seq_len, hidden_dim)
class JarvisTitanMoEDecoderLayer(Qwen2DecoderLayer):
def __init__(self, config: JarvisTitanMoEConfig, layer_idx: int):
super().__init__(config, layer_idx)
self.mlp = DeepSeekMoEMLP(config)
class JarvisTitanMoEModel(Qwen2Model):
config_class = JarvisTitanMoEConfig
def __init__(self, config: JarvisTitanMoEConfig):
super().__init__(config)
self.layers = nn.ModuleList([
JarvisTitanMoEDecoderLayer(config, i) for i in range(config.num_hidden_layers)
])
self.post_init()
class JarvisTitanMoEForCausalLM(Qwen2ForCausalLM):
config_class = JarvisTitanMoEConfig
def __init__(self, config: JarvisTitanMoEConfig):
super().__init__(config)
self.model = JarvisTitanMoEModel(config)
self.post_init()
|