paiml/aprender/find-contracts
Claude Code and agent skill by paiml/aprender
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Find which provable-contracts YAML contracts a Hugging Face model needs, create missing contracts, generate Rust artifacts, and implement all stubs. Triggers on: "find contracts", "contract coverage", "what contracts does X need", "which contracts for", HF model analysis, model contract gap analysis.
Install
npx vskill@latest install paiml/aprender/find-contractsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
Find Contracts for a Hugging Face Model
Full pipeline: analyze a Hugging Face model's config.json, determine required contracts, create missing YAML contracts, generate Rust artifacts, and implement all stubs to completion (zero-tolerance: no unimplemented!() or SATD markers).
Procedure
Step 1: Fetch the model config
Fetch the config using curl:
Error handling:
- 404: Report "Model not found: $ARGUMENTS — check the org/model-name spelling"
- 401/403: Report "Model is gated or private — you may need
huggingface-cli loginor request access at https://huggingface.co/$ARGUMENTS" - Non-JSON response: Report "Unexpected response — this may not be a valid HF model repo"
Parse the JSON and proceed to field extraction.
Step 2: Extract architecture fields
Extract these fields from config.json (use null for missing fields):
| Field | Purpose | |
|---|---|---|
model_type | Architecture family | |
architectures | Model class list | |
hidden_act / activation_function | Activation function | |
hidden_size | Model dimension | |
intermediate_size | FFN inner dimension | |
num_attention_heads | Query head count | |
num_key_value_heads | KV head count (GQA if != num_attention_heads) | |
num_hidden_layers | Layer count | |
vocab_size | Vocabulary size | |
rope_theta | RoPE base frequency | |
rope_scaling | RoPE scaling config | |
partial_rotary_factor | Partial RoPE (Phi-style) | |
rms_norm_eps | RMSNorm epsilon (implies RMSNorm) | |
layer_norm_eps / layer_norm_epsilon | LayerNorm epsilon (implies LayerNorm) | |
sliding_window | Sliding window attention size | |
tie_word_embeddings | Tied input/output embeddings | |
qk_layernorm / qk_norm | QK normalization | |
attn_logit_softcapping | Attention logit capping (Gemma2) | |
multi_query | Multi-query attention (Falcon) | |
parallel_attn | Parallel attention (Falcon) | |
use_alibi / alibi | ALiBi position encoding | |
ssm_cfg / d_state / d_conv | SSM/Mamba fields |
Step 3: Map fields to required contracts
Use the mapping in config-to-contract-mapping.md.
Three categories:
A) Universal contracts — every transformer LLM needs these 13:
model-config-algebra-v1softmax-kernel-v1matmul-kernel-v1linear-projection-v1embedding-lookup-v1embedding-algebra-v1tensor-shape-flow-v1cross-entropy-kernel-v1inference-pipeline-v1attention-kernel-v1attention-scaling-v1kv-cache-sizing-v1kv-cache-equivalence-v1
B) Conditional contracts — triggered by specific config values. See the full mapping table in config-to-contract-mapping.md.
Key rules:
hidden_act=silu→silu-kernel-v1+swiglu-kernel-v1(most SiLU models use SwiGLU FFN)hidden_actcontainsgelu→gelu-kernel-v1rms_norm_epspresent →rmsnorm-kernel-v1layer_norm_epspresent →layernorm-kernel-v1rope_thetapresent →rope-kernel-v1rope_scalingnot null →rope-extrapolation-v1partial_rotary_factorpresent →rope-kernel-v1+absolute-position-v1num_key_value_heads != num_attention_heads→gqa-kernel-v1sliding_windowset →sliding-window-attention-v1qk_layernormorqk_normtrue →qk-norm-v1attn_logit_softcappingset →attention-scaling-v1(already universal, but note capping variant)tie_word_embeddingstrue →tied-embeddings-v1use_alibioralibitrue →alibi-kernel-v1- SSM fields present →
ssm-kernel-v1 - GatedDeltaNet architecture →
gated-delta-net-v1+hybrid-layer-dispatch-v1+conv1d-kernel-v1
See known-architectures.md for edge cases (Falcon multi_query, Phi partial_rotary_factor, Gemma2 softcapping, DeepSeek MLA, etc.).
C) Model-specific contracts — always check for these:
<model_type>-shapes-v1.yaml(e.g.,qwen35-shapes-v1.yaml)<model_type>-e2e-verification-v1.yaml(e.g.,qwen35-e2e-verification-v1.yaml)
For the model name normalization: use model_type from config, lowercase, replace hyphens with nothing. Examples: llama, qwen2, mistral, phi, gemma2, falcon.
Step 4: Check existing contracts
Glob contracts/*.yaml in the project root to get the list of all existing contracts. Compare against the required set from Step 3.
Step 5: Output gap analysis
Format the output in four sections:
A) Model Config Summary
Only include fields that are present (non-null).
B) Contract Coverage Matrix
Status values: EXISTS, MISSING, N/A (not needed for this model).
C) Gap Statistics
D) Missing Contract Details
For each MISSING contract, output:
Step 6: Create missing model-specific YAML contracts
If any model-specific contracts are MISSING (<model>-shapes-v1.yaml or <model>-e2e-verification-v1.yaml), create them using the extracted config fields.
Use existing contracts as templates. Read a similar contract from contracts/ (e.g., qwen2-shapes-v1.yaml for a new shapes contract) and adapt:
- Replace config constants (hidden_size, num_attention_heads, etc.) with the
target model's values from Step 2
- Recompute all derived values (d_k = hidden/n_heads, gqa_ratio, expansion_ratio, etc.)
- Adjust proof obligations, falsification tests, and kani harnesses for the new constants
- Write to
contracts/<model>-shapes-v1.yamland/orcontracts/<model>-e2e-verification-v1.yaml
YAML structure (required sections):
Skip this step for MISSING universal/conditional contracts — those are generic and must be authored manually by the team.
Step 7: Generate Rust artifacts
For each newly created model-specific YAML contract, generate Rust artifacts:
This produces 4 files per contract:
generated/<model>-shapes-v1_scaffold.rs— trait definitiongenerated/<model>-shapes-v1_kani.rs— Kani proof harnessesgenerated/<model>-shapes-v1_probar.rs— property + falsification testsgenerated/<model>-shapes-v1_book.md— documentation page
Step 8: Implement all generated stubs
ZERO-TOLERANCE: Every `unimplemented!()`, `todo!()`, and SATD marker must be replaced with complete implementations. The pre-commit hook will reject any commit containing these markers.
For each generated .rs file:
Probar files (_probar.rs)
- Define model config constants at file top level (outside
#[cfg(test)]module):
``rust #[allow(dead_code)] const HIDDEN: usize = <hidden_size>; const N_HEADS: usize = <num_attention_heads>; // ... all config constants from the YAML ``
- Replace every
unimplemented!("Wire up: ...")with deterministic arithmetic:
- Shape invariants:
assert_eq!(N_HEADS * D_K, HIDDEN) - Divisibility:
assert_eq!(N_HEADS % N_KV_HEADS, 0) - RoPE monotonicity: compute freq vector, assert
freqs[i] > freqs[i+1] - Parameter count: sum all weight shapes, assert within expected range
- Memory ordering: compute Q4K/Q6K/F16/F32, assert strict ordering
- Throughput monotonicity: tok/s = bandwidth / model_bytes, assert monotonic
- Replace every
unimplemented!("Implement falsification test for ..."):
- Deterministic tests: assert literal constants match (e.g.,
28 * 128 == 3584) - Parametric tests: sweep over multiple configs/values to stress the property
- RoPE tests: sweep over multiple (base, d_k) pairs
Kani files (_kani.rs)
- Shape harnesses: use symbolic
kani::any()with bounded assumptions:
``rust let n_h: usize = kani::any(); kani::assume(n_h >= 1 && n_h <= 64); kani::assume(n_h % n_kv == 0); // ... verify algebraic properties hold for ALL valid configs ``
- Param count harnesses: use concrete model constants, verify total in expected range
- Quant ordering harnesses: use symbolic
n, verifyn*9 < n*13 < n*32 < n*64
(bits scaled by 2 to avoid floating point)
Scaffold files (_scaffold.rs)
- Add config constants after the trait definition
- Add a concrete struct (e.g.,
pub struct LlamaShapesVerifier;) - Implement all trait methods with real computation writing results to
output
Step 9: Compile and verify
Compile all generated files standalone to confirm no stubs remain:
All probar tests must pass. All scaffolds must compile with zero warnings.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 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 repositoryCheckingcrates/aprender-contracts-staging/.claude/skills/find-contracts/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
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/paiml/aprender/find-contracts)