quark-torch-shrink-model
SkillDocs & knowledgeLets your agent shrink a HuggingFace safetensors model down to one hidden layer for quick debugging.
Available today. Use it from your connected AI after setup.
No other account needed.
Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.
Then ask your AI: use the quark-torch-shrink-model skill
About this skill
Shrink a HuggingFace safetensors model to 1 hidden layer for fast debugging without loading the full model into memory. Use when the user wants to create a minimal model for debugging, reduce a large model to its smallest valid structure, generate a tiny model for testing Quark workflows, or validat
What this skill tells your AI
The instructions your AI receives, as published by amd/quark in skills/quark-torch-shrink-model/SKILL.md and read by ahel’s review.
Purpose
Produce a minimal 1-layer copy of any HuggingFace safetensors model for debugging Quark
workflows. The tool reads model.safetensors.index.json to determine layer structure and
rewrites only the necessary shards — the full model is never loaded into memory.
Non-layer weights (embeddings, final norm, lm_head) are always preserved so the output
is a structurally valid model that can be loaded with transformers.
Inputs
source_model_directory— local directory containing safetensors files andconfig.jsondestination_model_directory— where to write the shrunk modeltest_mode(optional) — if the user wants only JSON files without tensor data, for structural validation
How to invoke
Understand the user's intent first
Ask (or infer from context):
- Source path: where is the model? (required)
- Destination path: where to save the shrunk model? (required)
- Test mode?: does the user just want to validate the structure without writing tensors?
- "quick check", "just test", "no tensors", "only json" → use
--test - "real model", "load and run", "actual weights" → full mode (no
--test)
- "quick check", "just test", "no tensors", "only json" → use
CLI invocation
The script lives in the skill directory and is invoked directly by path:
SKILL_DIR="skills/_legacy_impl/l1-atomic/torch/quark-torch-shrink-model"
# Full shrink (writes real safetensors shards)
python "$SKILL_DIR/shrink_model.py" \
--src /path/to/source/model \
--dst /path/to/output/tiny_model
# Test mode (JSON only, no safetensors — fast structural validation)
python "$SKILL_DIR/shrink_model.py" \
--src /path/to/source/model \
--dst /path/to/output/tiny_model \
--test
Python API
import sys
from pathlib import Path
skill_dir = Path("skills/_legacy_impl/l1-atomic/torch/quark-torch-shrink-model")
sys.path.insert(0, str(skill_dir))
from shrink_model import shrink_model
shrink_model(
source_model_directory=Path("/path/to/source/model"),
destination_model_directory=Path("/path/to/output/tiny_model"),
test_mode=False, # set True for JSON-only structural validation
)
Supported architectures
The tool auto-detects the layer naming convention from the weight keys:
| Pattern | Architectures |
|---|---|
model.layers.N. | LLaMA, Qwen, Mistral, Gemma, DeepSeek-V3/R1 |
layers.N. (no prefix) | DeepSeek-V4 |
transformer.h.N. | GPT-2, Falcon |
model.blocks.N. | MPT |
model.transformer.layer.N. | BERT-style |
If the user's model uses a different pattern, add a new entry to _LAYER_INDEX_PATTERNS
in skills/_legacy_impl/l1-atomic/torch/quark-torch-shrink-model/shrink_model.py.
Output: shrink_result.md
After running, produce a brief report:
## Shrink Result
- **Source**: /path/to/source/model
- **Destination**: /path/to/output/tiny_model
- **Mode**: full / test
- **Layers detected**: 80 (0 ... 79)
- **Layer kept**: 0 → remapped to 0
- **Keys kept**: 12 / 723
- **config.json**: num_hidden_layers 80 → 1
- **Status**: success
If the run fails, include the error and the most likely fix:
| Error | Likely Cause | Fix |
|---|---|---|
Could not detect any layer indices in weight_map | Unsupported key naming | Add pattern to _LAYER_INDEX_PATTERNS |
Neither model.safetensors.index.json nor model.safetensors found in | Wrong source path | Verify --src points to the model directory |
ImportError: safetensors is required: pip install safetensors | safetensors not installed | pip install safetensors |
Signals
- GitHub stars
- 174
- Forks
- 35
- Last commit
- Sep 2026
ahel review
K1binfo
installs-packages
Automated review, not a security audit. Ruleset v1+k2.
Advanced
- Item type
- skill
- Key
quark-torch-shrink-model- Source
- github.com/amd/quark