Skip to content
Agentmart
Submit a tool

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

IndexedMIT★ 186
Write a review

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.

Book a call

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.

We use your email only for this newsletter. Privacy

About

Shrink a HuggingFace safetensors model to 1 hidden layer for fast debugging without loading the full model into memory.

Use cases: ml

No 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

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
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from amd

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.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying quark-torch-shrink-model?

CallGet help
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)