agentleFS
ByteDance-SeedByteDance-Seed/VeOmni/.agents/skills/veomni-gpu-to-npu/SKILL.md

veomni-gpu-to-npu

Skill2.3k starsChanged 3 days agoApache-2.0View on GitHub

Plan and migrate an existing VeOmni GPU model implementation to Ascend NPU. Use when the GPU patchgen path already works and the model needs a migration file inventory, dependency auditing, NPU operator selection, patchgen integration, multimodal wrapper adaptation, or focused model tests. Gemma 3 is the worked example.

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 5 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read these references before changing model code:

    line 10
  2. Very specific:

    Use veomni/models/transformers/qwen3/, seed_oss/, qwen3_vl/, and qwen3_5/ as reference implementations.

    line 20
  3. Distinctive:

    Before editing code, report a migration file inventory and ordered implementation steps.

    line 26
  4. Very specific:

    Check device-neutral behavior as part of the audit: allocations must derive their device from inputs or parameters, no .cuda() calls may …

    line 62
  5. Distinctive:

    Prefer an NPU sibling patch spec that reuses the complete device-neutral GPU patch.

    line 68
  6. Very specific:

    Update __init__.py so model classes are selected at import time by device availability.

    line 98
  7. Very specific:

    Read .agents/skills/veomni-patchgen-model/references/multimodal.md, then audit the vision or audio tower, multimodal projector, placeholder …

    line 113
  8. Very specific:

    Verify the checkpoint namespace as well as the operator namespace.

    line 115
  9. Very specific:

    Keep the multimodal forward contract intact.

    line 119
  10. Distinctive:

    When replacing the outer VLM loss, preserve the upstream shifted-label and attention-mask behavior.

    line 123
  11. Very specific:

    Run the same patchgen command twice and require the second run to leave the generated .py and .diff unchanged.

    line 135
  12. Distinctive:

    Run focused checks for the patch spec and generated model before hardware training.

    line 137

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

VeOmni GPU-to-NPU Model Migration

Produce the smallest maintainable NPU model implementation for a model that already works through VeOmni's GPU path. Keep this skill limited to model code, generated patches, registry dispatch, and focused model validation; do not add training configs, launch scripts, datasets, logs, plots, reports, or checkpoints.

Read these references before changing model code:

  • .agents/knowledge/constraints.md
  • .agents/skills/veomni-patchgen-model/SKILL.md
  • .agents/skills/veomni-new-op/SKILL.md
  • docs/design/patchgen.md
  • docs/design/op_selection.md
  • veomni/ops/README.md
  • .agents/knowledge/testing.md

Use veomni/models/transformers/qwen3/, seed_oss/, qwen3_vl/, and qwen3_5/ as reference implementations. Gemma 3 under veomni/models/transformers/gemma3/ is the dense text/VLM worked example.

1. Audit The Existing Model Patch

Confirm that the installed Transformers version matches the repository pin, then inspect the GPU patch spec, generated model, upstream Transformers model, model registry, and the live operator registry.

Before editing code, report a migration file inventory and ordered implementation steps. Include only files needed for model adaptation; identify files that can be reused unchanged and explain why any expected patch, test, or registry file is unnecessary.

FilePurposePlanned changeValidation
veomni/models/transformers/<model>/...NPU patch spec or model dispatchAdd or update the minimum NPU-specific codePatchGen, import, and focused model tests
veomni/models/transformers/<model>/generated/...Generated NPU model artifactRegenerate from the patch spec; never edit by handRun PatchGen twice and check for no diff
tests/models/...Model adaptation coverageExtend the closest existing test when neededRun the focused test

Adjust the rows to the target model. Do not add a file just to match this example; record an explicit no-change decision when an existing implementation already covers it.

python -c "import transformers; print(transformers.__version__)"
rg -n "transformers==" pyproject.toml
ls veomni/models/transformers/<model>/{__init__.py,*_gpu_patch_gen_config.py}
ls veomni/models/transformers/<model>/generated/patched_modeling_*_gpu.py

rg -n "cuda|triton|flash_attention|flex_attention|liger|is_cuda|\.cuda\(" \
  veomni/models/transformers/<model>

rg -n "VeomniOp|ops_config|attn_implementation|RMSNorm|apply_rotary|cross_entropy" \
  veomni/models/transformers/<model> \
  veomni/ops/kernels

For every patched operator, verify the registered implementations and select the NPU backend according to the exact model semantics rather than the backend name alone.

OperationTypical GPU backendTypical NPU choice
attentionflex_attention / flash attentionsdpa or eager
RMSNormliger_kerneltorch_npu when the variant matches
rotary embeddingliger_kerneltorch_npu
causal cross entropyliger_kernelchunk_loss or eager
SwiGLUfused GPU backendregistered NPU backend or eager
MoEfused_tritonfused_npu
load-balancing losstritonregistered NPU backend or eager

Check device-neutral behavior as part of the audit: allocations must derive their device from inputs or parameters, no .cuda() calls may remain, dtype conversions must preserve the model contract, and distributed operations must use VeOmni's current parallel-state APIs.

Model-specific normalization and loss semantics are correctness-critical. Select the registry variant whose tensor contract matches the model: standard RMSNorm uses the standard variant, while Gemma 3 initializes weights to zero and uses the offset variant to apply 1 + weight. Do not apply that offset again in model code. Likewise, verify soft-capping, ignored labels, shifted labels, and reduction behavior before replacing the upstream loss.

2. Implement The NPU Patch

Prefer an NPU sibling patch spec that reuses the complete device-neutral GPU patch. Add only NPU/VLM behavior that is absent from the GPU path.

from copy import deepcopy

from veomni.models.transformers.<model>.<model>_gpu_patch_gen_config import config as gpu_config


config = deepcopy(gpu_config)
config.target_file = "patched_modeling_<model>_npu.py"
config.description = "<Model> with VeomniOp NPU replacements"

Model classes must own instance-local VeomniOp handles. Resolve the configured implementation from config.ops_config during construction and call the handle unconditionally; the registry's eager row supplies the CPU/GPU fallback.

from veomni.ops import VeomniOp


rms_norm_impl = config.ops_config.rms_norm_implementation if config is not None else "eager"
self.veomni_rms_norm = VeomniOp(
    "rms_norm",
    "standard",
    rms_norm_impl,
)
hidden_states = self.veomni_rms_norm(hidden_states, self.weight, eps=self.variance_epsilon)

Inspect OP_REGISTRY before adding an implementation. If the required (op, variant, implementation) row is missing, follow veomni-new-op: implement it under veomni/ops/kernels, register it with register_op, attach NpuKernelRequirement(), and keep model-specific argument adaptation in the PatchGen model. Never import a vendor kernel directly from generated modeling. Do not duplicate a GPU patch body merely to change its target file.

Update __init__.py so model classes are selected at import time by device availability.

from ....utils.device import IS_NPU_AVAILABLE

if IS_NPU_AVAILABLE:
    from .generated.patched_modeling_<model>_npu import <classes>
else:
    from .generated.patched_modeling_<model>_gpu import <classes>

Register every supported model_type and preserve the existing architecture fallback behavior. A VLM normally requires one registry entry for its multimodal wrapper and another for its text backbone.

3. Adapt Multimodal Model Wrappers

Read .agents/skills/veomni-patchgen-model/references/multimodal.md, then audit the vision or audio tower, multimodal projector, placeholder masks, packed metadata, sequence-parallel boundaries, and the outer ForConditionalGeneration.forward independently from the text backbone.

Verify the checkpoint namespace as well as the operator namespace. Nested generated wrappers can change parameter names even when the upstream class loads correctly, so compare source checkpoint keys with model.named_parameters() after constructing the generated wrapper and add an explicit conversion mapping when required.

For the Gemma 3 VLM, legacy keys under language_model.model.*, vision_tower.vision_model.*, and multi_modal_projector.* map to the generated wrapper's nested model.* names. Treat unexpected keys or uninitialized vision/projector parameters as hard failures; a tied lm_head alias may be the only intentional exception.

Keep the multimodal forward contract intact. Gemma 3 requires pixel_values and image-aware token_type_ids in addition to the text tensors, and its model-specific position-ID function must remain compatible with VeOmni's packing and sequence-parallel paths.

For distributed training, account for ranks that receive text-only microbatches while peer ranks receive multimodal data. Disable unused trainable auxiliary heads, run a minimal dummy forward through every modality component used by the real media path, and attach the result to the text path with a zero-valued dependency. Verify that real-media and text-only microbatches touch the same trainable modality parameters so DDP/FSDP reductions remain symmetric without changing logits or loss.

When replacing the outer VLM loss, preserve the upstream shifted-label and attention-mask behavior. Do not treat successful text-backbone execution as coverage for the multimodal wrapper.

4. Generate And Validate Model Artifacts

Generate model files through patchgen and never edit generated/ by hand.

patchgen veomni.models.transformers.<model>.<model>_npu_patch_gen_config \
  -o veomni/models/transformers/<model>/generated --diff -v
git diff --check

Run the same patchgen command twice and require the second run to leave the generated .py and .diff unchanged.

Run focused checks for the patch spec and generated model before hardware training.

python -m py_compile \
  veomni/models/transformers/<model>/<model>_npu_patch_gen_config.py \
  veomni/models/transformers/<model>/generated/patched_modeling_<model>_npu.py

python -c "import veomni.models.transformers.<model>.generated.patched_modeling_<model>_npu"
make quality

Extend an existing model test when practical. Cover generated-module import, local VeomniOp selection, eager parity, finite forward/backward outputs, gradients, checkpoint conversion, multimodal input propagation when applicable, and patchgen reproducibility. Verify that constructing another model with a different ops configuration does not retarget handles on the first model.

Completion Checklist

  • Installed Transformers version matches the repository pin
  • GPU-only model dependencies are classified
  • Device-neutral allocations, dtype conversions, and distributed APIs are verified
  • NPU backends are verified in the live operator registry
  • Every model-side operator is an instance-local VeomniOp; no module-global dispatch remains
  • Model-specific normalization and loss semantics are preserved
  • NPU patch spec reuses device-neutral GPU patch bodies
  • Text and multimodal model types are registered as applicable
  • Multimodal checkpoint namespaces and input contracts are verified
  • Real-media and text-only distributed microbatches touch the same trainable modality parameters
  • Generated model and diff are reproducible
  • Import, quality, and focused model tests pass
  • No configs, scripts, datasets, logs, plots, reports, or checkpoints are included

Download now (ZIP)

Trending

Quiet since September.about the whole repository

Dec 2025: 1 mentionJan 2026: 0 mentionsFeb 2026: 1 mentionMar 2026: 0 mentionsApr 2026: 1 mentionMay 2026: 2 mentionsJun 2026: 3 mentionsJul 2026: 0 mentionsAug 2026: 4 mentionsSep 2026: 5 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the ByteDance-Seed/VeOmni repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about ByteDance-Seed/VeOmni

The biggest 5 of 22 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 22

Talked about on GitHub and Bluesky (22 times).

On GitHub · 21

16 more on GitHub

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.