quark-torch-shrink-model
Shrink a HuggingFace safetensors model to 1 hidden layer for fast debugging without loading the full model into memory.
Skill by amd
Chalk Labs
Need help deploying quark-torch-shrink-model?
Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/amd-quark-torch-shrink-model-732a44
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: ml
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
- Runs as
- Python package
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/quark-torch-shrink-model
What's inside
- Skill name
quark-torch-shrink-model- Description
- Shrink a HuggingFace safetensors model to 1 hidden layer for fast debugging without loading the full model into memory.
- License
- MIT
- Instructions
- 106 lines in SKILL.md · view on GitHub
Before installing
- Ships executable scripts
Files (2)
- SKILL.md
- shrink_model.py
SKILL.md (first lines)
# quark-torch-shrink-model
## 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 and `config.json`
- `destination_model_directory` — where to write the shrunk model
- `test_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):
1. **Source path**: where is the model? (required)
2. **Destination path**: where to save the shrunk model? (required)
3. **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`)
### CLI invocation
The script lives in the skill directory and is invoked directly by path:
```bash
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
```python
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:
```markdown
## 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` |From amd/Quark, MIT.
More from amd/Quark
- 0.684score
quark-skill-creator
amd
Author or restructure a Quark Agent Skill so it conforms to this project's template, contracts, and layer rules.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-torch-llm-eval
amd
End-to-end LLM accuracy evaluation on AMD ROCm (ROCm-only) — container setup, vLLM/SGLang/ATOM serving, lm-eval / lighteval / evalscope benchmarks.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-env-preflight
amd
Collect and normalize environment facts (OS, Python, GPU, CUDA/ROCm, container state) before Quark installation or PTQ planning.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-torch-model-intake
amd
Inspect a target model and prepare metadata for Quark PTQ planning.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-torch-export
amd
Prepare export and downstream evaluation handoff for a planned or completed Quark PTQ run.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-torch-install
amd
Install or verify the correct PyTorch build for a user's accelerator backend before Quark installation.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-install
amd
Install or verify the AMD Quark package and its dependencies.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-onnx-install
amd
Install or verify the correct ONNX Runtime build (and the `onnx` package) for a user's accelerator backend before Quark's ONNX-to-ONNX flow.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-onnx-model-intake
amd
Inspect a target ONNX model and prepare metadata for Quark ONNX PTQ planning.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-onnx-router
amd
Route Quark ONNX user goals to the correct atomic skill.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-torch-debug
amd
Diagnose failed Quark installation, PTQ execution, script generation, or export attempts.
SkillAFreshness: A★ 186Claude Code +9 - 0.679score
quark-torch-quant-plan
amd
Build a Quark Torch LLM PTQ quantization plan from model analysis and user intent.
SkillAFreshness: A★ 186Claude Code +9
Signals
- Stars
- 186
- Forks
- 36
- Open issues
- 3
- Last commit (this folder)
- Sep 28, 2026 (1 month ago)
- Last release
- Sep 28, 2026 (1 month ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/amd/Quark
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from amd
- 0.700score
quark-torch-llm-ptq
amd
Runs an end-to-end AMD Quark post-training quantization workflow for PyTorch / Hugging Face LLMs: inspect a Hub or local model, choose a quantization plan…
SkillAFreshness: A★ 465Claude Code +9 - 0.700score
rocprofiler-pc-sampling
amd
Profiles a target application using rocprofv3 with program counter sampling enabled and then analyzes the results.
SkillAFreshness: A★ 465Claude Code +9 - 0.700score
local-ai-use
amd
Makes this agent generate images, transcribe audio, and synthesize speech on the user's own machine through a local Lemonade Server instead of a paid cloud API.
SkillAFreshness: A★ 465Claude Code +9 - 0.700score
quark-install
amd
Installs or verifies AMD Quark and ensures the selected Python environment has an accelerator-matched PyTorch.
SkillAFreshness: A★ 465Claude Code +9 - 0.700score
lemonade-router-builder
amd
Turns a natural-language description of routing intent into a valid Lemonade `collection.router` policy JSON.
SkillAFreshness: A★ 465Claude Code +9 - 0.700score
serving-llms-on-epyc
amd
Serves an LLM on a supported AMD EPYC server CPU using vLLM with zentorch, in Docker, Podman, or conda.
SkillAFreshness: A★ 465Claude Code +9
Done for you
Rather not set it up yourself?
Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.
See how we build AI agents →Read the case studies
Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.
- launches shipped
- 50+
- launches shipped
- media placements
- 500+
- media placements
- founders on every account
- 2
- founders on every account
Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block
Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.
Get quark-torch-shrink-model running in your business
Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.
Cite this page
quark-torch-shrink-model skill. Agent Mart. https://agentmart.dev/skills/amd-quark-torch-shrink-model-732a44 (last updated 2026-10-24)