migrate-max-v2-to-v3
Use when migrating a MAX model from the V2 graph API (max.nn.legacy, TensorValue, explicit Graph construction) to ModuleV3 (max.nn, Tensor, F.lazy() +…
от modular★ 215 звёзд на GitHub
Установить migrate-max-v2-to-v3 в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Migrate a MAX model from V2 to ModuleV3
Input: the V2 model source to migrate ($ARGUMENTS).
ModuleV3 (max.nn) is the current MAX model API. A V2 model
builds an explicit Graph over TensorValue values with layers from
max.nn.legacy. A ModuleV3 model declares a forward() over Tensor values and
compiles with F.lazy() + compile(). Read
references/v2-v3-basics.md first. It covers
F.lazy(), compile(weights=...), dtype handling with auto_cast,
forward() vs __call__(), the distributed mapping, and the import
rules.
For architecture serving integration, read the
module registration compatibility reference.
Prefer supported ModuleV3 role registration without an architecture-specific
PipelineModel. The standalone compilation examples below explain the model
API; the registration runtime owns those steps for registered architectures.
Keep a custom pipeline for a documented unsupported task, backend or feature.
Draft/speculator module registration has not been added.
Workflow
1. Confirm the model is V2
Classify by imports, and read the file when grep and the imports disagree.
V2 code imports its layers from max.nn.legacy and builds an explicit Graph
over TensorValue. ModuleV3 code imports max.nn and
subclasses its Module. Scoped greps shortcut the read:
grep -rn "max.experimental" <model-path>
grep -rEn "^\s*(from|import) max\.nn" <model-path>
Hits from the first mean the model is already (at least partly) V3 and
needs review, not migration. Hits from the second mean V2. Imports from
max.graph alone don't decide: V3 code keeps TensorType and
DeviceRef from max.graph for input specs. A file that hits both is
mixed. Read it before migrating anything.
2. Keep the V2 code, add the V3 variant
Leave the V2 implementation untouched so it keeps working while the V3
variant is under construction. Put the V3 code alongside it: a
<name>_modulev3 directory when migrating a registered architecture, or a
new module file when the model lives in your own package. When migrating a
registered architecture, name the V3 variant with the _ModuleV3 suffix.
max serve --prefer-module-v3 selects it while the V2 name keeps serving
by default.
3. Rewrite imports
# REMOVE:
from max.graph import Graph, TensorValue, BufferValue, ops
from max.nn.legacy.layer import Module, LayerList
from max.nn.legacy.linear import Linear
from max.nn.legacy.norm.rms_norm import RMSNorm
# ADD:
from max import functional as F
from max.tensor import Tensor
from max.nn import Module
from max.nn.linear import Linear
from max.nn.norm import RMSNorm
from max.nn.sequential import ModuleList
# KEEP (TensorValue-free, shared with V2):
from max.nn.kv_cache import KVCacheParams, KVCacheParamInterface
from max.nn.attention_mask import MHAMaskVariant
TensorTypeandDeviceRefstay frommax.graph. They define input specs, not graph values.max.nn.legacyimports are fine when the imported class doesn't useTensorValue.PagedCacheValuescomes frommax.nn.common_layers.kv_cachefor the V3 type.max.nn.legacyexports aPagedCacheValuesof its own, an alias for the V2 input type withoutfrom_upstream(). Import from themax.experimentalpath to get the V3 type.
4. Rewrite the module surface
__call__()becomesforward().TensorValueandBufferValuebecomeTensor.Moduletakes the call signature:class MyModel(Module[[Tensor, ...], tuple[Tensor, ...]]). Prefer specific types, and use...only whenforward()has*args.- Layer constructors take keyword args and drop
dtype=anddevice=. V3 uses default dtype and device contexts, andmodel.to(device)moves the module to one device after construction. LayerListbecomesModuleListfrommax.nn.sequential.ModuleListsubclasseslist, so it takes a single iterable:ModuleList(layers).ModuleList(*layers)raisesTypeError.- Parameters are plain
Tensorobjects. Create them withTensor.zeros(),max.functional.random.*, and similar factories.
5. Rewrite operations
ops.* becomes F.* (ops.gather() → F.gather()). Most shape ops are
methods on Tensor: reshape(), transpose(), permute(), squeeze(),
unsqueeze(), split(), cast(). flatten() is the exception. It's
functional-only (F.flatten(tensor, start_dim)).
6. Replace graph building with compile()
V2:
nn_model = MyModel(config)
nn_model.load_state_dict(state_dict)
with Graph("my_model", input_types=input_types) as graph:
outputs = nn_model(*graph.inputs)
graph.output(*outputs)
model = session.load(graph, weights_registry=state_dict)
V3:
with F.lazy():
nn_model = MyModel(config)
nn_model.to(device)
model = nn_model.compile(*input_types, weights=state_dict)
F.lazy()wraps construction and records weight tensors symbolica
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/module-registration.md
- references/v2-v3-basics.md
FAQ
Что делает скилл migrate-max-v2-to-v3?
Use when migrating a MAX model from the V2 graph API (max.nn.legacy, TensorValue, explicit Graph construction) to ModuleV3 (max.nn, Tensor, F.lazy() + compile()). Triggers on: "migrate to ModuleV3", "port a max.nn.legacy model to max.experimental", "convert TensorValue to Tensor", "update my model to the V3 API", "ModuleV3 migration". Workflow: read the concept map, rewrite imports and __call__ signatures, and replace graph building with compile(weights=...). Align weight names with the new module hierarchy and move the KV cache unflatten into forward(). Port sharding to a DeviceMesh when the V2 model is sharded, then verify greedy outputs match the V2 implementation.
Как установить скилл migrate-max-v2-to-v3?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл migrate-max-v2-to-v3 запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…