GLM 4.1V 9B MLX 4bit
これはTHUDM/GLM-4.1V-9B-Thinkingから変換されたMLX形式のモデルで、視覚言語タスクをサポートします。
ダウンロード数 114
リリース時間 : 7/17/2025
モデル概要
このモデルはTHUDM/GLM-4.1V-9B-Thinkingから変換され、MLX形式を採用し、視覚言語の理解と生成タスクをサポートします。
モデル特徴
MLX形式サポート
モデルはMLX形式に変換され、Appleチップデバイスに適しています。
4ビット量子化
モデルは4ビット量子化処理を経て、メモリ使用量を削減しています。
視覚言語能力
画像理解と画像に基づくテキスト生成をサポートします。
モデル能力
視覚言語の理解
画像説明生成
視覚質問応答
マルチモーダル推論
使用事例
コンテンツ生成
画像説明生成
入力画像に基づいて詳細な説明を生成します。
スマート質問応答
視覚質問応答
画像内容に関する質問に回答します。
🚀 Rainnighttram/GLM-4.1V-9B-MLX-4bit
このモデル Rainnighttram/GLM-4.1V-9B-MLX-4bit は、THUDM/GLM-4.1V-9B-Thinking から mlx-lm バージョン 0.26.0 を使用して MLX 形式に変換されました。
🚀 クイックスタート
注意事項
これはモデルの公式リポジトリではなく、公式のサポートは提供されていません。モデルをロードするには、MLX-VLM パッケージを手動で調整する必要があります。現在、変換とモデルのロードには問題や混乱が生じる可能性があります。
📦 インストール
pip install mlx-lm mlx-vlm mlx torchvision
モデルファイルの設定
mlx-vlm のモデルファイルを "models" ディレクトリ配下で設定します。
mkdir glm4v
cd glm4v
必須モデルファイルの作成
nano __init__.py
# ファイル: mlx_vlm/models/glm4v/__init__.py
from .glm4v import Model, ModelConfig
from .language import LanguageModel, TextConfig
from .vision import VisionModel, VisionConfig
# 保存して終了
nano language.py
# ファイル: language.py
import inspect
from dataclasses import dataclass
from typing import Any, Optional, Dict, List, Tuple
import mlx.core as mx
import mlx.nn as nn
from ..base import (
create_attention_mask,
scaled_dot_product_attention,
)
# Define the complete output class with all optional attributes the generator might check for.
@dataclass
class CausalLMOutput:
logits: mx.array
cross_attention_states: Optional[Tuple] = None
encoder_outputs: Optional[Tuple] = None
hidden_states: Optional[Tuple] = None
attentions: Optional[Tuple] = None
@dataclass
class TextConfig:
model_type: str
hidden_size: int
num_hidden_layers: int
intermediate_size: int
num_attention_heads: int
attention_bias: bool
rms_norm_eps: float
vocab_size: int
num_key_value_heads: int
partial_rotary_factor: float
rope_theta: float
rope_traditional: bool = True
max_position_embeddings: int = 65536
@classmethod
def from_dict(cls, params):
return cls(
**{
k: v
for k, v in params.items()
if k in inspect.signature(cls).parameters
}
)
class Glm4MLP(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.gate_up_proj = nn.QuantizedLinear(
args.hidden_size, 2 * args.intermediate_size, bias=False
)
self.down_proj = nn.QuantizedLinear(
args.intermediate_size, args.hidden_size, bias=False
)
def __call__(self, x) -> mx.array:
x = self.gate_up_proj(x)
gate, up_states = mx.split(x, 2, axis=-1)
return self.down_proj(nn.silu(gate) * up_states)
class Glm4Attention(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.head_dim = args.hidden_size // args.num_attention_heads
self.n_heads = args.num_attention_heads
self.n_kv_heads = args.num_key_value_heads
self.scale = self.head_dim ** -0.5
bias = args.attention_bias
q_out = args.num_attention_heads * self.head_dim
kv_out = args.num_key_value_heads * self.head_dim
self.q_proj = nn.QuantizedLinear(args.hidden_size, q_out, bias=bias)
self.k_proj = nn.QuantizedLinear(args.hidden_size, kv_out, bias=bias)
self.v_proj = nn.QuantizedLinear(args.hidden_size, kv_out, bias=bias)
self.o_proj = nn.QuantizedLinear(q_out, args.hidden_size, bias=False)
self.rope = nn.RoPE(
dims=int(self.head_dim * args.partial_rotary_factor),
base=args.rope_theta,
traditional=args.rope_traditional,
)
def __call__(
self, x: mx.array, mask: Optional[mx.array] = None, cache: Optional[Any] = None
) -> mx.array:
B, L, D = x.shape
queries, keys, values = self.q_proj(x), self.k_proj(x), self.v_proj(x)
queries = queries.reshape(B, L, self.n_heads, -1).transpose(0, 2, 1, 3)
keys = keys.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
values = values.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
if cache is not None:
queries = self.rope(queries, offset=cache.offset)
keys = self.rope(keys, offset=cache.offset)
keys, values = cache.update_and_fetch(keys, values)
else:
queries = self.rope(queries)
keys = self.rope(keys)
output = scaled_dot_product_attention(
queries, keys, values, cache=cache, scale=self.scale, mask=mask
)
output = output.transpose(0, 2, 1, 3).reshape(B, L, -1)
return self.o_proj(output)
class Glm4DecoderLayer(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.self_attn = Glm4Attention(args=args)
self.mlp = Glm4MLP(args)
self.input_layernorm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps)
self.post_attention_layernorm = nn.RMSNorm(
args.hidden_size, eps=args.rms_norm_eps
)
self.post_self_attn_layernorm = nn.RMSNorm(
args.hidden_size, eps=args.rms_norm_eps
)
self.post_mlp_layernorm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps)
def __call__(
self, x: mx.array, mask: Optional[mx.array] = None, cache: Optional[Any] = None
) -> mx.array:
x = x + self.post_self_attn_layernorm(
self.self_attn(self.input_layernorm(x), mask, cache)
)
residual = x
x = (
self.post_mlp_layernorm(self.mlp(self.post_attention_layernorm(x)))
+ residual
)
return x
class Glm4Model(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.embed_tokens = nn.QuantizedEmbedding(args.vocab_size, args.hidden_size)
self.layers = [
Glm4DecoderLayer(args=args) for _ in range(args.num_hidden_layers)
]
self.norm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps)
def __call__(
self,
inputs: mx.array,
mask: Optional[mx.array] = None,
cache: Optional[Any] = None,
inputs_embeds: Optional[mx.array] = None,
):
if inputs_embeds is not None:
h = inputs_embeds
else:
h = self.embed_tokens(inputs)
if mask is None:
mask = create_attention_mask(h, cache)
if cache is None:
cache = [None] * len(self.layers)
for layer, c in zip(self.layers, cache):
h = layer(h, mask, cache=c)
return self.norm(h)
class LanguageModel(nn.Module):
def __init__(self, config: TextConfig):
super().__init__()
self.config = config
self.model_type = config.model_type
self.model = Glm4Model(config)
self.lm_head = nn.QuantizedLinear(config.hidden_size, config.vocab_size, bias=False)
def __call__(
self,
inputs: mx.array,
inputs_embeds: Optional[mx.array] = None,
mask: Optional[mx.array] = None,
cache=None,
):
out = self.model(inputs, inputs_embeds=inputs_embeds, mask=mask, cache=cache)
out = self.lm_head(out)
# --- THIS IS THE FIX ---
# Return a consistent object type
return CausalLMOutput(logits=out)
@property
def layers(self):
return self.model.layers
# 保存して終了
nano vision.py
# ファイル: vision.py
import inspect
from dataclasses import dataclass
from typing import Any, Optional, Dict, List, Tuple
import mlx.core as mx
import mlx.nn as nn
from ..base import (
create_attention_mask,
scaled_dot_product_attention,
)
# Define the complete output class with all optional attributes the generator might check for.
@dataclass
class CausalLMOutput:
logits: mx.array
cross_attention_states: Optional[Tuple] = None
encoder_outputs: Optional[Tuple] = None
hidden_states: Optional[Tuple] = None
attentions: Optional[Tuple] = None
@dataclass
class TextConfig:
model_type: str
hidden_size: int
num_hidden_layers: int
intermediate_size: int
num_attention_heads: int
attention_bias: bool
rms_norm_eps: float
vocab_size: int
num_key_value_heads: int
partial_rotary_factor: float
rope_theta: float
rope_traditional: bool = True
max_position_embeddings: int = 65536
@classmethod
def from_dict(cls, params):
return cls(
**{
k: v
for k, v in params.items()
if k in inspect.signature(cls).parameters
}
)
class Glm4MLP(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.gate_up_proj = nn.QuantizedLinear(
args.hidden_size, 2 * args.intermediate_size, bias=False
)
self.down_proj = nn.QuantizedLinear(
args.intermediate_size, args.hidden_size, bias=False
)
def __call__(self, x) -> mx.array:
x = self.gate_up_proj(x)
gate, up_states = mx.split(x, 2, axis=-1)
return self.down_proj(nn.silu(gate) * up_states)
class Glm4Attention(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.head_dim = args.hidden_size // args.num_attention_heads
self.n_heads = args.num_attention_heads
self.n_kv_heads = args.num_key_value_heads
self.scale = self.head_dim ** -0.5
bias = args.attention_bias
q_out = args.num_attention_heads * self.head_dim
kv_out = args.num_key_value_heads * self.head_dim
self.q_proj = nn.QuantizedLinear(args.hidden_size, q_out, bias=bias)
self.k_proj = nn.QuantizedLinear(args.hidden_size, kv_out, bias=bias)
self.v_proj = nn.QuantizedLinear(args.hidden_size, kv_out, bias=bias)
self.o_proj = nn.QuantizedLinear(q_out, args.hidden_size, bias=False)
self.rope = nn.RoPE(
dims=int(self.head_dim * args.partial_rotary_factor),
base=args.rope_theta,
traditional=args.rope_traditional,
)
def __call__(
self, x: mx.array, mask: Optional[mx.array] = None, cache: Optional[Any] = None
) -> mx.array:
B, L, D = x.shape
queries, keys, values = self.q_proj(x), self.k_proj(x), self.v_proj(x)
queries = queries.reshape(B, L, self.n_heads, -1).transpose(0, 2, 1, 3)
keys = keys.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
values = values.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
if cache is not None:
queries = self.rope(queries, offset=cache.offset)
keys = self.rope(keys, offset=cache.offset)
keys, values = cache.update_and_fetch(keys, values)
else:
queries = self.rope(queries)
keys = self.rope(keys)
output = scaled_dot_product_attention(
queries, keys, values, cache=cache, scale=self.scale, mask=mask
)
output = output.transpose(0, 2, 1, 3).reshape(B, L, -1)
return self.o_proj(output)
class Glm4DecoderLayer(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.self_attn = Glm4Attention(args=args)
self.mlp = Glm4MLP(args)
self.input_layernorm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps)
self.post_attention_layernorm = nn.RMSNorm(
args.hidden_size, eps=args.rms_norm_eps
)
self.post_self_attn_layernorm = nn.RMSNorm(
args.hidden_size, eps=args.rms_norm_eps
)
self.post_mlp_layernorm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps)
def __call__(
self, x: mx.array, mask: Optional[mx.array] = None, cache: Optional[Any] = None
) -> mx.array:
x = x + self.post_self_attn_layernorm(
self.self_attn(self.input_layernorm(x), mask, cache)
)
residual = x
x = (
self.post_mlp_layernorm(self.mlp(self.post_attention_layernorm(x)))
+ residual
)
return x
class Glm4Model(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.embed_tokens = nn.QuantizedEmbedding(args.vocab_size, args.hidden_size)
self.layers = [
Glm4DecoderLayer(args=args) for _ in range(args.num_hidden_layers)
]
self.norm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps)
def __call__(
self,
inputs: mx.array,
mask: Optional[mx.array] = None,
cache: Optional[Any] = None,
inputs_embeds: Optional[mx.array] = None,
):
if inputs_embeds is not None:
h = inputs_embeds
else:
h = self.embed_tokens(inputs)
if mask is None:
mask = create_attention_mask(h, cache)
if cache is None:
cache = [None] * len(self.layers)
for layer, c in zip(self.layers, cache):
h = layer(h, mask, cache=c)
return self.norm(h)
class LanguageModel(nn.Module):
def __init__(self, config: TextConfig):
super().__init__()
self.config = config
self.model_type = config.model_type
self.model = Glm4Model(config)
self.lm_head = nn.QuantizedLinear(config.hidden_size, config.vocab_size, bias=False)
def __call__(
self,
inputs: mx.array,
inputs_embeds: Optional[mx.array] = None,
mask: Optional[mx.array] = None,
cache=None,
):
out = self.model(inputs, inputs_embeds=inputs_embeds, mask=mask, cache=cache)
out = self.lm_head(out)
# --- THIS IS THE FIX ---
# Return a consistent object type
return CausalLMOutput(logits=out)
@property
def layers(self):
return self.model.layers
# 保存して終了
nano glmv4.py
# ファイル: glmv4.py
import inspect
from dataclasses import dataclass
from typing import Any, Optional, Dict, List, Tuple
import mlx.core as mx
import mlx.nn as nn
from ..base import (
create_attention_mask,
scaled_dot_product_attention,
)
# Define the complete output class with all optional attributes the generator might check for.
@dataclass
class CausalLMOutput:
logits: mx.array
cross_attention_states: Optional[Tuple] = None
encoder_outputs: Optional[Tuple] = None
hidden_states: Optional[Tuple] = None
attentions: Optional[Tuple] = None
@dataclass
class TextConfig:
model_type: str
hidden_size: int
num_hidden_layers: int
intermediate_size: int
num_attention_heads: int
attention_bias: bool
rms_norm_eps: float
vocab_size: int
num_key_value_heads: int
partial_rotary_factor: float
rope_theta: float
rope_traditional: bool = True
max_position_embeddings: int = 65536
@classmethod
def from_dict(cls, params):
return cls(
**{
k: v
for k, v in params.items()
if k in inspect.signature(cls).parameters
}
)
class Glm4MLP(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.gate_up_proj = nn.QuantizedLinear(
args.hidden_size, 2 * args.intermediate_size, bias=False
)
self.down_proj = nn.QuantizedLinear(
args.intermediate_size, args.hidden_size, bias=False
)
def __call__(self, x) -> mx.array:
x = self.gate_up_proj(x)
gate, up_states = mx.split(x, 2, axis=-1)
return self.down_proj(nn.silu(gate) * up_states)
class Glm4Attention(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.head_dim = args.hidden_size // args.num_attention_heads
self.n_heads = args.num_attention_heads
self.n_kv_heads = args.num_key_value_heads
self.scale = self.head_dim ** -0.5
bias = args.attention_bias
q_out = args.num_attention_heads * self.head_dim
kv_out = args.num_key_value_heads * self.head_dim
self.q_proj = nn.QuantizedLinear(args.hidden_size, q_out, bias=bias)
self.k_proj = nn.QuantizedLinear(args.hidden_size, kv_out, bias=bias)
self.v_proj = nn.QuantizedLinear(args.hidden_size, kv_out, bias=bias)
self.o_proj = nn.QuantizedLinear(q_out, args.hidden_size, bias=False)
self.rope = nn.RoPE(
dims=int(self.head_dim * args.partial_rotary_factor),
base=args.rope_theta,
traditional=args.rope_traditional,
)
def __call__(
self, x: mx.array, mask: Optional[mx.array] = None, cache: Optional[Any] = None
) -> mx.array:
B, L, D = x.shape
queries, keys, values = self.q_proj(x), self.k_proj(x), self.v_proj(x)
queries = queries.reshape(B, L, self.n_heads, -1).transpose(0, 2, 1, 3)
keys = keys.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
values = values.reshape(B, L, self.n_kv_heads, -1).transpose(0, 2, 1, 3)
if cache is not None:
queries = self.rope(queries, offset=cache.offset)
keys = self.rope(keys, offset=cache.offset)
keys, values = cache.update_and_fetch(keys, values)
else:
queries = self.rope(queries)
keys = self.rope(keys)
output = scaled_dot_product_attention(
queries, keys, values, cache=cache, scale=self.scale, mask=mask
)
output = output.transpose(0, 2, 1, 3).reshape(B, L, -1)
return self.o_proj(output)
class Glm4DecoderLayer(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.self_attn = Glm4Attention(args=args)
self.mlp = Glm4MLP(args)
self.input_layernorm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps)
self.post_attention_layernorm = nn.RMSNorm(
args.hidden_size, eps=args.rms_norm_eps
)
self.post_self_attn_layernorm = nn.RMSNorm(
args.hidden_size, eps=args.rms_norm_eps
)
self.post_mlp_layernorm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps)
def __call__(
self, x: mx.array, mask: Optional[mx.array] = None, cache: Optional[Any] = None
) -> mx.array:
x = x + self.post_self_attn_layernorm(
self.self_attn(self.input_layernorm(x), mask, cache)
)
residual = x
x = (
self.post_mlp_layernorm(self.mlp(self.post_attention_layernorm(x)))
+ residual
)
return x
class Glm4Model(nn.Module):
def __init__(self, args: TextConfig):
super().__init__()
self.embed_tokens = nn.QuantizedEmbedding(args.vocab_size, args.hidden_size)
self.layers = [
Glm4DecoderLayer(args=args) for _ in range(args.num_hidden_layers)
]
self.norm = nn.RMSNorm(args.hidden_size, eps=args.rms_norm_eps)
def __call__(
self,
inputs: mx.array,
mask: Optional[mx.array] = None,
cache: Optional[Any] = None,
inputs_embeds: Optional[mx.array] = None,
):
if inputs_embeds is not None:
h = inputs_embeds
else:
h = self.embed_tokens(inputs)
if mask is None:
mask = create_attention_mask(h, cache)
if cache is None:
cache = [None] * len(self.layers)
for layer, c in zip(self.layers, cache):
h = layer(h, mask, cache=c)
return self.norm(h)
class LanguageModel(nn.Module):
def __init__(self, config: TextConfig):
super().__init__()
self.config = config
self.model_type = config.model_type
self.model = Glm4Model(config)
self.lm_head = nn.QuantizedLinear(config.hidden_size, config.vocab_size, bias=False)
📄 ライセンス
このモデルは MIT ライセンスの下で提供されています。
Clip Vit Large Patch14 336
Vision Transformerアーキテクチャに基づく大規模な視覚言語事前学習モデルで、画像とテキストのクロスモーダル理解をサポートします。
テキスト生成画像
Transformers

C
openai
5.9M
241
Fashion Clip
MIT
FashionCLIPはCLIPを基に開発された視覚言語モデルで、ファッション分野に特化してファインチューニングされ、汎用的な製品表現を生成可能です。
テキスト生成画像
Transformers 英語

F
patrickjohncyh
3.8M
222
Gemma 3 1b It
Gemma 3はGoogleが提供する軽量で先進的なオープンモデルシリーズで、Geminiモデルと同じ研究と技術に基づいて構築されています。このモデルはマルチモーダルモデルであり、テキストと画像の入力を処理し、テキスト出力を生成できます。
テキスト生成画像
Transformers

G
google
2.1M
347
Blip Vqa Base
Bsd-3-clause
BLIPは統一された視覚言語事前学習フレームワークで、視覚質問応答タスクに優れており、言語-画像共同トレーニングによりマルチモーダル理解と生成能力を実現
テキスト生成画像
Transformers

B
Salesforce
1.9M
154
CLIP ViT H 14 Laion2b S32b B79k
MIT
OpenCLIPフレームワークを使用してLAION-2B英語データセットでトレーニングされた視覚-言語モデルで、ゼロショット画像分類とクロスモーダル検索タスクをサポートします
テキスト生成画像
Safetensors
C
laion
1.8M
368
CLIP ViT B 32 Laion2b S34b B79k
MIT
OpenCLIPフレームワークを使用し、LAION-2B英語サブセットでトレーニングされた視覚-言語モデルで、ゼロショット画像分類とクロスモーダル検索をサポート
テキスト生成画像
Safetensors
C
laion
1.1M
112
Pickscore V1
PickScore v1はテキストから生成された画像に対するスコアリング関数で、人間の選好予測、モデル性能評価、画像ランキングなどのタスクに使用できます。
テキスト生成画像
Transformers

P
yuvalkirstain
1.1M
44
Owlv2 Base Patch16 Ensemble
Apache-2.0
OWLv2はゼロショットテキスト条件付き物体検出モデルで、テキストクエリを使用して画像内のオブジェクトを位置特定できます。
テキスト生成画像
Transformers

O
google
932.80k
99
Llama 3.2 11B Vision Instruct
Llama 3.2はMetaがリリースした多言語マルチモーダル大規模言語モデルで、画像テキストからテキストへの変換タスクをサポートし、強力なクロスモーダル理解能力を備えています。
テキスト生成画像
Transformers 複数言語対応

L
meta-llama
784.19k
1,424
Owlvit Base Patch32
Apache-2.0
OWL-ViTはゼロショットのテキスト条件付き物体検出モデルで、特定カテゴリの訓練データなしにテキストクエリで画像内のオブジェクトを検索できます。
テキスト生成画像
Transformers

O
google
764.95k
129
おすすめAIモデル
Llama 3 Typhoon V1.5x 8b Instruct
タイ語専用に設計された80億パラメータの命令モデルで、GPT-3.5-turboに匹敵する性能を持ち、アプリケーションシナリオ、検索拡張生成、制限付き生成、推論タスクを最適化
大規模言語モデル
Transformers 複数言語対応

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-TinyはSODAデータセットでトレーニングされた超小型対話モデルで、エッジデバイス推論向けに設計されており、体積はCosmo-3Bモデルの約2%です。
対話システム
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
RoBERTaアーキテクチャに基づく中国語抽出型QAモデルで、与えられたテキストから回答を抽出するタスクに適しています。
質問応答システム 中国語
R
uer
2,694
98