ai-modcon/prism/prism-adding-a-modality
Claude Code and agent skill by ai-modcon/prism
- community
Checking that the SKILL.md file is still in the repository.
Add a new modality (encoder + projector) to PRISM end-to-end. Use when writing a new ModalityEncoder subclass, registering a projector, extending the Modality enum, wiring config fields, handling the token-merge path, or adding a dataset group for the modality. Triggers: "add a modality", "new encoder", "subclass ModalityEncoder", "ModalityProjector", "Modality enum", "tokens_per_instance", "merge modality embeds", "special modality token".
Install
npx vskill@latest install ai-modcon/prism/prism-adding-a-modalitySKILL.md
PRISM — Adding a Modality
A modality flows: raw input → `ModalityEncoder` → `ModalityProjector` → merged into the token sequence at special-token slots → LLM backbone. Adding one touches ~6 files in a fixed pattern. Full step-by-step: `references/encoder-checklist.md`.
The pattern (files you'll touch)
| Step | File | What | |
|---|---|---|---|
| 1 | src/encoders/<mod>.py | Subclass ModalityEncoder (base: src/encoders/base.py) | |
| 2 | src/modules/projector.py | Reuse ModalityProjector — usually no change | |
| 3 | src/modalities.py | Add member to the Modality enum + ALL_MODALITIES | |
| 4 | src/config.py | Add d_<mod> dim + projector fields to ModelConfig | |
| 5 | src/model.py | Instantiate encoder/projector; handle the merge slot | |
| 6 | src/conf/data/*.yaml + sharding | Add a dataset group (see prism-data-pipeline) |
Encoder contract (src/encoders/base.py)
tokens_per_instance() is load-bearing for the merge: it tells model.py how many token slots one instance expands to (e.g. time-series expands to 256). Existing encoders: image, text, table, time_series, geometry (+ FallbackGeometryEncoder), graph.
Projector (src/modules/projector.py)
ModalityProjector(input_dim, d_model, norm_mode=..., ...). Norm modes: none, layernorm, rmsnorm, l2_token, l2_sequence, scale_only, match_text_stats, match_text_elemstats. Depth/width via hidden_mult, num_layers (the IsoFLOP variant ladder BASE/W2X/W4X/D2X/D4X lives here). Configured through projector_* fields on ModelConfig.
Merge path (src/model.py, _merge_text_input_ids_with_modality_embeds, ~line 533)
Special modality tokens (IDs in config.modality_start_end_token_indices) are replaced by encoder outputs; slot size = encoders[mod].tokens_per_instance(). UnifiedTransformer.__init__ (~lines 221–354) instantiates encoders/projectors conditionally per config.modalities into nn.ModuleDicts.
Gotchas learned the hard way
- Tokenizer resize must use the LLM tokenizer + grow-only. Resizing
embeddings with the base tokenizer (50304→50280) shrinks the table; the modality special token (e.g. <ts>=50280) then indexes out of bounds → a delayed XPU write-fault/segfault (issue #117). Always resize with llm_tokenizer_id and never shrink.
- Budget the *total* merged sequence length, not just the modality tokens.
An oversized merged sequence OOMs the 64 GB XPU tile (attention ≈ O(T²), cliff ~4608 tokens), surfacing as a drm_neo page-fault under DDP+oneCCL — not an obvious OOM (issues #120/#122/#123). Cap variates at the data path AND reserve headroom for text. A model-layer fail-loud guard before the backbone forward is the follow-up (#123).
- `--max-seq-length 4096 // 256 = 16 = all variates`, so a per-modality
variate cap can be inert; the real fix budgets merged length end-to-end.
Verify
Add a smoke config and run a 1-node smoke (see prism-launching-jobs --dry-run first). Confirm the encoder's tokens land at the right slots and loss decreases.
See also
- Deep references: `docs/api/encoders.md`,
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingdocs/skills/prism-adding-a-modality/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ai-modcon/prism/prism-adding-a-modality)