简介
Port a model's config and modeling code into gptqmodel/models/ports on the Transformers 5.23 ABI, with no transformers.models.* imports, no checkpoint Python and no backward-compatibility paths. Use when adding a model, alias or definition, or when editing any port.
通过你的 Agent 添加
安装目录:gptqmodel-model-porting/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
技能正文
SPDX-FileCopyrightText: 2026 ModelCloud.ai
SPDX-License-Identifier: Apache-2.0
name: gptqmodel-model-porting
description: Port a model's config and modeling code into gptqmodel/models/ports on the Transformers 5.23 ABI, with no transformers.models.* imports, no checkpoint Python and no backward-compatibility paths. Use when adding a model, alias or definition, or when editing any port.
Model porting on the Transformers 5.23 ABI
The contract
name: gptqmodel-model-porting description: Port a model's config and modeling code into gptqmodel/models/ports on the Transformers 5.23 ABI, with no transformers.models.* imports, no checkpoint Python and no backward-compatibility paths. Use when adding a model, alias or definition, or when editing any port.
The contract
GPT-QModel quantizes, runs inference and trains only on the Transformers
5.23 ABI (transformers>=5.23.0,<5.24; the vendored ABI is pinned per
Transformers minor, so a bump means re-vendoring plus parity, see
docs/transformers5-model-ports.md). Every supported model is selected by its definition's
LocalModelLoader and runs GPT-QModel's own config and modeling code from
gptqmodel/models/ports/<port>/. There are no exceptions:
- Every
MODEL_MAPdefinition has aLocalModelLoader. No definition loads throughAutoModel*,AutoConfig, checkpointauto_maportrust_remote_code. A model that Transformers implements natively is still ported, so a Transformers upgrade cannot change GPT-QModel's math, module names or state_dict keys. - Ports import Transformers framework infrastructure only. Allowed:
PreTrainedModel,PreTrainedConfig,cache_utils(Cache,DynamicCache, cache layers),masking_utils,ALL_ATTENTION_FUNCTIONS/modeling_flash_attention_utils,modeling_rope_utils,modeling_layers(GradientCheckpointingLayer),generation(GenerationMixin, generation config),activations,modeling_outputs,initialization,integrations,processing_utils,tokenization_utils_*/TokenizersBackend,image_processing_utils*,feature_extraction_utils,utils. Nothing fromtransformers.models.*: not a config, block, norm, MLP, attention, rotary, vision tower, processor or helper function. Copy what you need into the port. - 5.23 conventions only, zero back-compat. Write the port the way 5.23
native models are written (read
models/qwen3/modeling_qwen3.pyandmodels/qwen3_5/modeling_qwen3_5.pyin the 5.23 source):- positions from
position_ids/past_key_values.get_seq_length(); nocache_positionparameters or bookkeeping; - caches are
Cachesubclasses or 5.23 cache layers; kwargpast_key_values; no tuple caches,from_legacy_cache,to_legacy_cache,get_usable_length,seen_tokens,_reorder_cache; - masks from
masking_utils(create_causal_mask,create_sliding_window_causal_mask,create_bidirectional_mask, ...); no_prepare_4d_*,AttentionMaskConverter,_update_causal_mask; - attention through
ALL_ATTENTION_FUNCTIONS/eager_attention_forward; layers subclassGradientCheckpointingLayer; - outputs via
@merge_with_config_defaults,@capture_outputs,_can_record_outputsand@can_return_tuple; no manualall_hidden_states/all_self_attns,use_return_dict, orif not return_dict: return tuple(...); - config fields
rope_parameters,dtype,layer_types; heads takelogits_to_keep;_tied_weights_keysis a dict; - weight init through
transformers.initialization; - no
_supports_cache_class/_supports_static_cache/_supports_quantized_cache/_supports_flash_attn_2, no version checks, notry/except ImportErroraround Transformers symbols. A releasedconfig.jsonmay still contain an old field such asrope_scaling; convert it once at config-parse time. Nothing downstream reads the old name.
- positions from
- No global changes to Transformers. Ports never register with
AutoConfig/AutoModel, and GPT-QModel never patches, monkeypatches or registers into Transformers or the HF ecosystem (optimum, OpenVINO, safetensors, huggingface_hub), not even temporarily or scoped. GPT-QModel checkpoints load throughGPTQModel.load.tests/test_transformers_unpatched.pyenforces this. - Checkpoint fidelity. Keep the released checkpoint's state_dict keys, numerics and module names. A port reproducing a non-native original keeps that original's math; a port of a Transformers-native family must match Transformers 5.23 exactly.
Procedure
- Source. Start from the 5.23 implementation (native family) or the
pinned original release (non-native). Record the source path/revision in
the port's
NOTICE. Keep upstream copyright headers.
- Vendor. Create
gptqmodel/models/ports/<port>/ with __init__.py,
configuration_<port>.py, modeling_<port>.py (plus processor/tokenizer
modules if the definition loads them). Rewrite relative imports to the
allowed framework modules above; replace every transformers.models.*
import with local code (cross-family pieces such as a SigLIP tower are
copied into the port that uses them, or into a shared port that both
import).
- Bind. Give the definition a
LocalModelLoader(config_class=..., model_class=..., processor_class=..., tokenizer_class=...); set
config_architectures only for released configs that omit model_type.
- Prove it.
- Native-family oracle: on a tiny random config, the port's logits,
generated tokens (cached generation vs no-cache full forward) and
state_dict keys/shapes equal Transformers 5.23's native class exactly.
The oracle may import
transformers.models.* in tests only.
- Release inventory: the full-size meta model's key/shape inventory
matches the released checkpoint index (store a sha256, not the JSON).
- Routed experts and packed vision. When an expert representation changes,
hand-label physical rows in released checkpoint order. Use distinct gate
and up values and a fractional routing weight that distinguishes BF16
rounding before and after multiplication. Compare each executable route
with the same hand-computed output. For packed vision, use unequal image
lengths and an explicit per-image, per-head attention oracle. Mark learned
positions on a rectangular patch grid that spans two merge blocks.
- Isolation: loads without
trust_remote_code and without the bypass,
and ignores a hostile auto_map.
- Plans: module-plan tests and an explicit AWQ policy
(model-plan tests,
AWQ onboarding).
- Guard:
tests/test_model_port_policy.py passes (it fails on any
transformers.models.* import in a port, any stale 4.x pattern, or any
definition without a LocalModelLoader).
- Keep it lean. Ship only runtime code/data in the package. Test fixtures
live under
tests/fixtures/ports/<port>/; prefer digests to large JSON.
NOTICE. Keep upstream copyright headers.gptqmodel/models/ports/<port>/ with __init__.py,
configuration_<port>.py, modeling_<port>.py (plus processor/tokenizer
modules if the definition loads them). Rewrite relative imports to the
allowed framework modules above; replace every transformers.models.*
import with local code (cross-family pieces such as a SigLIP tower are
copied into the port that uses them, or into a shared port that both
import).LocalModelLoader(config_class=..., model_class=..., processor_class=..., tokenizer_class=...); set
config_architectures only for released configs that omit model_type.- Native-family oracle: on a tiny random config, the port's logits,
generated tokens (cached generation vs no-cache full forward) and
state_dict keys/shapes equal Transformers 5.23's native class exactly.
The oracle may import
transformers.models.*in tests only. - Release inventory: the full-size meta model's key/shape inventory matches the released checkpoint index (store a sha256, not the JSON).
- Routed experts and packed vision. When an expert representation changes, hand-label physical rows in released checkpoint order. Use distinct gate and up values and a fractional routing weight that distinguishes BF16 rounding before and after multiplication. Compare each executable route with the same hand-computed output. For packed vision, use unequal image lengths and an explicit per-image, per-head attention oracle. Mark learned positions on a rectangular patch grid that spans two merge blocks.
- Isolation: loads without
trust_remote_codeand without the bypass, and ignores a hostileauto_map. - Plans: module-plan tests and an explicit AWQ policy (model-plan tests, AWQ onboarding).
- Guard:
tests/test_model_port_policy.pypasses (it fails on anytransformers.models.*import in a port, any stale 4.x pattern, or any definition without aLocalModelLoader).
tests/fixtures/ports/<port>/; prefer digests to large JSON.