SkillAgentSearch skills...

convert-hf-to-te

Adapt a Hugging Face PyTorch model for training with compatible Transformer Engine modules. Replace a decoder layer, sublayer or individual operation and map its checkpoint weights. Choose fusions that preserve the requested workload's behavior.

Install / Use

npx skills add NVIDIA/skills --skill convert-hf-to-te

Installs into whichever agent you are using.

About this skill
📄

SKILL.md

Installable skill definition

Quality Score

88/100

Supported Platforms

Universal

Tags

Our assessment of convert-hf-to-te

convert-hf-to-te scores 88/100 on our quality scale, 440th of 956 AI & Machine Learning skills we index (top 47%).

Its SKILL.md is 16 KB long, well organised into 11 sections and no code examples: a thorough specification that gives an agent plenty to work with.

With 3,421 GitHub stars, it is one of the more widely adopted skills in the catalogue.

Substance
30/30
Structure
13/20
Description
15/15
Adoption
15/20
Freshness
15/15

Maintenance, license and trust

  • The repository was last updated about 2 months ago, so convert-hf-to-te is actively maintained.
  • It is released under the Apache-2.0 license, a permissive license that allows use, modification and commercial use with attribution.
  • Its trust signals score 100/100, with no cautions. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.

Safety scan

No issues found

Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands.

Automated pattern scan on 2026-11-27. It catches known dangerous patterns, not every risk — read a skill before letting an agent act on it.

convert-hf-to-te compared with similar skills

All 4 of these similar skills score higher than convert-hf-to-te; compare them before choosing.

SkillScoreStarsUpdatedFormat
convert-hf-to-te (this skill)by NVIDIA883.4k2mo agoSKILL.md
claude-memby thedotmack100120.2ktodayCLAUDE.md
archifyby tt-a1i100101.0ktodayCLAUDE.md
Understand-Anythingby Egonex-AI10094.7k3d agoCLAUDE.md
headroomby headroomlabs-ai10081.0ktodayCLAUDE.md

Frequently asked questions

How do I install convert-hf-to-te?
Run npx skills add NVIDIA/skills --skill convert-hf-to-te. The install tabs above show the steps for each supported agent.
Which AI agents does convert-hf-to-te work with?
It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
Is convert-hf-to-te safe to use?
Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. It is Apache-2.0-licensed and scores 100/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
Is convert-hf-to-te still maintained?
The repository was last updated about 2 months ago, so convert-hf-to-te is actively maintained.

name: convert-hf-to-te description: >- Adapt a Hugging Face PyTorch model for training with compatible Transformer Engine modules. Replace a decoder layer, sublayer or individual operation and map its checkpoint weights. Choose fusions that preserve the requested workload's behavior. license: Apache-2.0 allowed-tools: Bash, Read, Write, Edit, Glob, Grep compatibility: >- Writing the implementation needs no GPU. Running it needs transformer_engine[pytorch], transformers and an NVIDIA GPU. FP8 support depends on the recipe, GPU and backend. The training script may have other dependencies (the Llama tutorial also needs accelerate, datasets and peft). Newer models may need more, such as flash-linear-attention and causal-conv1d for Qwen3.5. metadata: version: "0.4.0" author: NVIDIA Transformer Engine contributors domain: model-training tags: - transformer-engine - hugging-face - pytorch - fine-tuning - mixture-of-experts

Convert a Hugging Face model to Transformer Engine

Use the project's requested entry point or add a model-family module such as te_llama.py. Replace compatible building blocks of the Hugging Face (HF) model with Transformer Engine (TE) modules and load the original checkpoint into them. The building block is the whole transformer layer, as for Llama and Gemma, or else the attention (MHA, linear attention) and MLP or MoE blocks inside it. A partial conversion can also replace a single operation inside an HF block. For a review or plan, stop after the requested feasibility, boundary or weight-mapping decision in Steps 1–3. For a local implementation, Step 4 ends at the first BF16 forward comparison. Use Step 5 for requested training checks, integration or performance measurements at the scope the user specified. In this skill te means transformer_engine.pytorch.

In a plan or implementation handoff, lead with the chosen replacement boundary and weight map.

Not for JAX or inference serving (vLLM, TensorRT-LLM). For Megatron-LM or another PyTorch framework, the TE implementation can serve as a reference for which TE modules to use and how the weights map.

1. Check the architecture and feasibility

Identify the training path, representative inputs and target precision from the request and project. Read the model's config.json, checkpoint keys and decoder forward at the requested revision or installed version. For each distinct layer type, record its modules, which tensors they consume or share, and their checkpoint keys. Use this inventory to identify candidate TE modules. Consult examples for the relevant boundary and verify API choices against the target TE release. For source-only work, use those sources to resolve API and layout questions before setting up a runtime.

| HF component | Candidate TE module | |---|---| | The whole transformer block | te.TransformerLayer | | Self-attention with QKV and output projections | te.MultiheadAttention. Set input_layernorm=True only when it replaces HF's input norm, so the norm runs once. | | Scaled dot-product attention on projected Q/K/V | te.DotProductAttention | | Input norm followed by one linear projection, which can pack compatible projections of the same normalized input | te.LayerNormLinear | | A norm and a dense MLP | te.LayerNormMLP | | Grouped linear projections across MoE experts | te.ops.GroupedLinear. The surrounding MoE block supplies activation and routing. | | Dispatch and combine across expert-parallel ranks | te.ops.MoeDispatch and te.ops.MoeCombine in the experimental operation fuser. Check compatibility with the router outputs and backend. | | A single projection or norm | te.Linear, te.RMSNorm, te.LayerNorm |

The table is not exhaustive. Newer architectures may need other TE modules, such as the experimental Gated DeltaNet core (te.GatedDeltaNetAttention). Check that the installed TE exports the candidate and its backend supports the target inputs and workload. Keep unsupported components in HF.

2. Choose the granularity

Start with the largest region that preserves HF's computation and the interface its caller uses. The level describes which part of the HF model you replace.

Level 1: the whole transformer block. Try one te.TransformerLayer for the HF decoder block. Match the attention and MLP widths, query and KV head counts, normalization and residual order, activation, mask, and rotary positions for the requested inputs. A causal HF decoder with only self-attention uses TE's self-attention topology with a causal mask. In TE 2.18, layer_type="decoder" adds cross-attention. When the block matches, substitute it at the HF decoder entry point and preserve the caller's arguments, layout and return value. Map the norm, attention and MLP weights and compare the whole block's BF16 output to HF in Step 4. Llama wrapper · Gemma constructor · TE layer topology

Level 2: attention and MLP separately. If the whole layer does not fit, consider each sublayer independently. Experts and linear attention are two examples from a non-exhaustive list.

  • Attention: use te.MultiheadAttention when it implements the target attention block.
  • MLP: te.LayerNormMLP for a dense MLP. For mixture-of-experts (MoE), compose a model-specific block around the compatible operations. For example, te_mixtral.py defines its own TEMixtralSparseMoeBlock to route tokens, run the expert FFN and combine outputs.

Level 3: an operation inside an HF sublayer. For example, replace a projection inside HF attention or the expert GEMMs inside an HF MoE block. Choose this boundary when you can preserve its inputs, outputs and shared state and have a workload benefit to test. If TE cannot reproduce the attention behavior, keep HF's attention computation, masking, positions and cache together. An independent MLP can still benefit. Keep HF wherever correctness or measured performance favors it.

Choose what to fuse

Choose fusions before mapping weights. Preserve operation order and all consumers of a shared tensor. For example, TE can combine:

  • a norm with the QKV projection: te.LayerNormLinear, or te.MultiheadAttention with input_layernorm=True;
  • a norm with the MLP: te.LayerNormMLP.

Look up other fusions in the PyTorch API and operation fuser guide. Check the installed release for support at the target shapes, dtype and hardware.

3. Map the weights

Use the Step 1 inventory and Step 2 boundaries to map each required HF key or slice to a TE parameter and slice. Record axis, order and intended cast where the layout changes. Preserve tied weights. For expert-parallel MoE, map each global expert ID to its owning rank and local expert parameter. When loading quantized weights into BF16, use the checkpoint's quantization metadata to recover the reference values.

Plan how the loader will track copies across all shards. Require it to fail on any missing required source or destination slice. For packed weights, reconstruct the named HF tensors after loading and compare after the intended cast to catch equal-shaped swaps. Three examples illustrate why the layout matters:

  • Llama gate and up fill separate FC1 halves and can arrive in different shards.
  • Gemma QKV uses different mappings for separate and interleaved projections.
  • Mixtral mappings pack Q heads by KV group and interleave expert gate/up rows for a fused kernel.

4. Implement

Design patterns

  • Substitute at construction when the replacement satisfies the HF caller. Keep the arguments, return values and state used by the workload so the surrounding HF model can call it directly. For example, Llama substitutes its decoder class while HF constructs the causal LM. Llama constructor
  • Compose around model-specific behavior when only part of a block matches. Keep routing or attention state with the code that owns it and attach TE at the boundary chosen in Step 2. For example, Mixtral dispatches routed tokens to its expert FFN, then combines its outputs. Mixtral MoE forward
  • Load after construction so the destination layout exists before applying the Step 3 mapping. Load retained HF parameters by their original mapping and verify the converted weights. For example, Gemma constructs the model before its standard loader maps the decoder weights and copies the retained embeddings. Gemma loader
  • Check each replacement's forward output first. After copying weights, run the original HF computation and its TE replacement in BF16 on the same representative inputs. Match relevant masks, positions, state and stochastic behavior. Choose tolerances for the quantities being compared before running the checks. Compare outputs at the same boundary and in the same layout. For example, for a fused norm and QKV projection, run the HF norm and all three HF projections, then arrange their outputs in the TE head order. A replacement constructed inside the model can be checked directly using captured layer inputs.

When replacement outputs differ

Choose checks that exercise the HF module being compared. These model-specific examples are non-exhaustive.

  • If attention outputs differ, compare the positions each path uses and which keys each query can see. Use an input that exercises the target behavior, such as a boundary in packed data.
  • A norm that multiplies by 1 + weight (Gemma, Qwen3.5) needs zero_centered_gamma=True.
  • Head sizes: pass the attention's real query/key and value head sizes as kv_channels. config.head_dim is not always that; in GLM-5 it is only the RoPE part of each head. For multi-head latent attention, check HF's effective softmax scale and which slice of Q and K receives rotary embeddings before substituting the attention core.
  • Match attention dropout and projection biases to HF. Check the installed module's defaults.
  • HF's post_init() overwrites TE weights; load the checkpoint before training.

5. Validation

Once the replacement outputs match, compare integrated HF and TE outputs on the same BF16 inputs and with the same stochastic controls. For training, match labels and loss reduction, then compare loss and a gradient or optimizer update on a replaced parameter in each changed path. Use the same parameter layout and exercise a routed expert for MoE. If the full model does n

Truncated for display — read the full file on GitHub.

Related Skills

View on GitHub
GitHub Stars3.4k
CategoryAI
Updated2mo ago
Forks412

Languages

Python

Trust signals

100/100

From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.

No cautions