Image-Text-to-Text
MLX
Safetensors
modilify_mk1
diffusion
multimodal
mixture-of-experts
conversational
Instructions to use modilify/Modilify-Mk1-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use modilify/Modilify-Mk1-MLX with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("modilify/Modilify-Mk1-MLX") config = load_config("modilify/Modilify-Mk1-MLX") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use modilify/Modilify-Mk1-MLX with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "modilify/Modilify-Mk1-MLX"
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": "modilify/Modilify-Mk1-MLX" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent
How to use modilify/Modilify-Mk1-MLX 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 "modilify/Modilify-Mk1-MLX"
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 modilify/Modilify-Mk1-MLX
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use modilify/Modilify-Mk1-MLX with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "modilify/Modilify-Mk1-MLX"
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 "modilify/Modilify-Mk1-MLX" \ --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"
| # Copyright 2026 Modilify | |
| # SPDX-License-Identifier: LicenseRef-Modilify-Open-Model-1.0 | |
| """Mk1 wrappers around the borrowed DiffusionGemma trunk layers. | |
| The trunk implementation is imported as an internal dependency. The public | |
| model type remains ``modilify_mk1``. Two Mk1-specific forwards are installed | |
| on the constructed trunk: | |
| * Router: softmax over all experts, then top-k and renormalize | |
| * Canvas merge: RMS-capped latent residual, not previous-logit soft embeds | |
| """ | |
| from __future__ import annotations | |
| import mlx.core as mx | |
| import mlx.nn as nn | |
| from mlx_vlm.models.diffusion_gemma.language import ( | |
| DiffusionGemma4Backbone, | |
| Router, | |
| geglu, | |
| ) | |
| LATENT_RESIDUAL_RMS_RATIO_CAP = 0.5 | |
| class Mk1Router(Router): | |
| """Official router weights with Mk1 log-softmax / top-k routing.""" | |
| def __call__(self, x: mx.array) -> tuple[mx.array, mx.array]: | |
| x = mx.fast.rms_norm(x, None, self.eps) | |
| x = x * self.scale * self._root_size | |
| scores = self.proj(x) | |
| probabilities = mx.softmax(scores, axis=-1, precise=True) | |
| top_k = self.config.top_k_experts | |
| indices = mx.argpartition(probabilities, kth=-top_k, axis=-1)[..., -top_k:] | |
| weights = mx.take_along_axis(probabilities, indices, axis=-1) | |
| weights = weights / mx.sum(weights, axis=-1, keepdims=True) | |
| weights = weights * self.per_expert_scale[indices] | |
| return indices, weights | |
| def merge_latent_context( | |
| mapper: nn.Module, | |
| token_embeddings: mx.array, | |
| latent_context: mx.array | None, | |
| *, | |
| rms_ratio_cap: float = LATENT_RESIDUAL_RMS_RATIO_CAP, | |
| ) -> mx.array: | |
| """Apply the native self-conditioning bridge with Mk1 RMS capping.""" | |
| context = ( | |
| mx.zeros_like(token_embeddings) | |
| if latent_context is None | |
| else latent_context.astype(token_embeddings.dtype) | |
| ) | |
| if context.shape != token_embeddings.shape: | |
| raise ValueError("Latent context must match the canvas embedding shape.") | |
| normalized = mapper.pre_norm(context) | |
| mapped = mapper.down_proj( | |
| geglu(mapper.gate_proj(normalized), mapper.up_proj(normalized)) | |
| ) | |
| mapped_rms = mx.sqrt( | |
| mx.mean(mx.square(mapped.astype(mx.float32)), axis=-1, keepdims=True) | |
| ) | |
| token_rms = mx.sqrt( | |
| mx.mean( | |
| mx.square(token_embeddings.astype(mx.float32)), axis=-1, keepdims=True | |
| ) | |
| ) | |
| cap = rms_ratio_cap * token_rms | |
| scale = cap / mx.sqrt(mx.square(mapped_rms) + mx.square(cap) + 1.0e-12) | |
| mapped = mapped * scale.astype(mapped.dtype) | |
| return mapper.post_norm(token_embeddings + mapped) | |
| def _install_mk1_embed_canvas(decoder: nn.Module) -> None: | |
| def _embed_canvas( | |
| canvas_ids, | |
| self_conditioning_logits=None, | |
| self_conditioning_embeddings=None, | |
| ): | |
| if self_conditioning_logits is not None: | |
| raise ValueError( | |
| "Modilify Mk1 uses latent embeddings, not logits self-conditioning." | |
| ) | |
| token_embeddings = decoder.embed_tokens(canvas_ids) * decoder.embed_scale | |
| return merge_latent_context( | |
| decoder.self_conditioning, | |
| token_embeddings, | |
| self_conditioning_embeddings, | |
| ) | |
| decoder._embed_canvas = _embed_canvas | |
| def _install_mk1_routers(backbone: DiffusionGemma4Backbone) -> None: | |
| for layer in backbone.decoder.layers: | |
| replacement = Mk1Router(layer.router.config) | |
| replacement.update(layer.router.parameters()) | |
| layer.router = replacement | |
| def build_mk1_backbone(trunk_config) -> DiffusionGemma4Backbone: | |
| """Construct the borrowed trunk and install Mk1 forwards.""" | |
| backbone = DiffusionGemma4Backbone(trunk_config) | |
| _install_mk1_routers(backbone) | |
| _install_mk1_embed_canvas(backbone.decoder) | |
| return backbone | |