Skip to content

Add GLM DSA package contract validation - #1032

Merged
i386 merged 2 commits into
mainfrom
jd/glm-dsa-package-contract
Jul 22, 2026
Merged

Add GLM DSA package contract validation#1032
i386 merged 2 commits into
mainfrom
jd/glm-dsa-package-contract

Conversation

@i386

@i386 i386 commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add GLM-DSA package contract validation for IndexShare metadata, Full/Shared roles, tensors, and generation policy thresholds
  • extend package preflight reports with generation policy and threshold checks
  • add repair support for package generation policy plus docs for the GLM-DSA runtime contract

Why

GLM-DSA layer packages need a machine-checkable contract before they are loaded in Skippy. This makes malformed IndexShare schedules, missing Full/Shared metadata, and missing generation policy thresholds fail before runtime rather than during lab execution.

Validation

  • cargo test -p skippy-model-package
  • cargo check -p skippy-model-package
  • cargo clippy -p skippy-model-package --all-targets -- -D warnings

Summary by CodeRabbit

  • New Features

    • Added GLM-DSA contract validation for GGUF inputs and model packages, checking required metadata, tensors, IndexShare roles, and generation-policy/thresholds (optional strict mode).
    • Added CLI commands to validate GLM-DSA contracts and repair missing GLM-DSA generation policy/thresholds.
    • Preflight output now includes generation policies and thresholds with stricter validation.
  • Bug Fixes / Improvements

    • Improved GLM-DSA KV-cache sizing/pricing behavior using newly supported GGUF metadata.
  • Documentation

    • Added a GLM-DSA runtime contract spec and expanded generation defaults/authoring guidance, including phase-aware contract rules.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request is currently a draft. Reviews will not take place until the PR is marked as ready for review.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e1764f6d-a205-48a6-aa7a-41c09a85fde5

📥 Commits

Reviewing files that changed from the base of the PR and between b2181ae and b120210.

📒 Files selected for processing (8)
  • crates/model-artifact/src/gguf.rs
  • crates/model-artifact/src/gguf/kv_cache.rs
  • crates/skippy-model-package/README.md
  • crates/skippy-model-package/src/generation_manifest.rs
  • crates/skippy-model-package/src/glm_dsa_contract.rs
  • crates/skippy-model-package/src/glm_dsa_generation_policy.rs
  • crates/skippy-model-package/src/main.rs
  • crates/skippy-model-package/src/preflight.rs
🚧 Files skipped from review as they are similar to previous changes (5)
  • crates/skippy-model-package/src/glm_dsa_generation_policy.rs
  • crates/skippy-model-package/README.md
  • crates/skippy-model-package/src/main.rs
  • crates/skippy-model-package/src/preflight.rs
  • crates/skippy-model-package/src/glm_dsa_contract.rs

📝 Walkthrough

Walkthrough

The changes add GLM-DSA GGUF cache-shape handling, a contract validator, generation-policy repair and preflight support, two CLI commands, and documentation for runtime and manifest requirements.

Changes

GLM-DSA support

Layer / File(s) Summary
GLM-DSA KV-cache shape derivation
crates/model-artifact/src/gguf.rs, crates/model-artifact/src/gguf/kv_cache.rs
GGUF metadata preserves kv_lora_rank, and GLM-DSA KV-cache byte calculations use adjusted head and value-length derivations with dedicated tests.
Generation manifest preflight and repair
crates/skippy-model-package/src/generation_manifest.rs, crates/skippy-model-package/src/preflight.rs, crates/skippy-model-package/src/glm_dsa_generation_policy.rs
Generation policy and threshold blocks are parsed, validated, reported, and repairable while preserving speculative-decoding settings.
GLM-DSA artifact contract validation
crates/skippy-model-package/src/glm_dsa_contract.rs
The validator collects GGUF artifacts, parses bounded metadata and tensors, validates generation settings and IndexShare roles, and returns structured errors and warnings.
CLI validation and repair commands
crates/skippy-model-package/src/cli.rs, crates/skippy-model-package/src/main.rs, crates/skippy-model-package/README.md
The package CLI exposes GLM-DSA contract validation and generation-policy repair commands with documented usage.
Runtime and manifest contract documentation
docs/specs/GLM_DSA_RUNTIME_CONTRACT.md, docs/specs/layer-package-repos.md, docs/LAYER_PACKAGE_REPOS.md
Documentation specifies GLM-DSA metadata, tensor, role, sideband, conversion, verification, and generation-manifest requirements.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant PackageCLI
  participant ArtifactCollector
  participant GGUFParser
  participant ContractValidator
  participant ManifestRepairer
  Operator->>PackageCLI: validate or repair package
  PackageCLI->>ArtifactCollector: collect GGUF artifacts
  ArtifactCollector->>GGUFParser: parse metadata and tensor names
  GGUFParser->>ContractValidator: provide artifact data
  ContractValidator-->>PackageCLI: return contract report
  PackageCLI->>ManifestRepairer: repair generation policy when requested
  ManifestRepairer-->>PackageCLI: write and revalidate manifest
  PackageCLI-->>Operator: print JSON result
Loading

Suggested reviewers: ndizazzo

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding GLM-DSA package contract validation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jd/glm-dsa-package-contract

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@i386
i386 marked this pull request as ready for review July 21, 2026 05:48
@github-actions
github-actions Bot requested a review from ndizazzo July 21, 2026 05:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/LAYER_PACKAGE_REPOS.md (1)

1-1: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Align the experimental policy docs with the model contract

generation.policy.experimental.moe_weighted_down and moe_merged_shared_gate_up are shown as manifest fields in both docs, but PackageGenerationExperimentalPolicy only models selected_row_flash, so the extra keys are currently ignored by serde and never validated. Either add them to crates/skippy-model-package/src/glm_dsa_contract.rs and crates/skippy-model-package/src/preflight.rs, or mark them as aspirational / not yet supported in the docs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/LAYER_PACKAGE_REPOS.md` at line 1, Align the documentation with the
supported model contract by marking
generation.policy.experimental.moe_weighted_down and moe_merged_shared_gate_up
as aspirational or not yet supported wherever they appear in the package
repository docs. Keep selected_row_flash documented as the currently modeled
field, and do not present the unsupported keys as validated manifest fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/model-artifact/src/gguf.rs`:
- Line 237: Extract the self-contained GgufKvCacheQuant KV-cache derivation
logic and its associated tests from gguf.rs into a new kv_cache module,
preserving its public API and behavior. Update imports and references so
existing callers continue to work, and ensure gguf.rs is reduced below 1,000
lines.

In `@crates/skippy-model-package/README.md`:
- Around line 49-50: Update the README command to use the
validate-glm-dsa-contract subcommand with the existing model-package argument.
Revise the write-package guidance to state that it writes only
speculative_decoding, while generation.policy and generation.thresholds are
added by repair-glm-dsa-generation-policy.
- Around line 67-82: Revise the README generation-handling section to clarify
that write-package only populates generation.speculative_decoding, while
generation.policy and generation.thresholds are supplied by
repair-glm-dsa-generation-policy. Preserve the guidance on versioned policy
profiles and evidence-based defaults without implying that write-package alone
completes the GLM-DSA contract.

In `@crates/skippy-model-package/src/glm_dsa_contract.rs`:
- Line 1: Extract the duplicated GLM-DSA policy/threshold constants and
generation manifest structs into one shared module, exposing them as pub(crate).
Update glm_dsa_contract, preflight, and glm_dsa_generation_policy—including
expected_policy() and expected_thresholds()—to import and use those shared
definitions, removing their local declarations.
- Around line 17-37: Add cross-field validation to validate_metadata after the
individual REQUIRED_U32_METADATA checks: require
glm-dsa.attention.indexer.key_length to be greater than
glm-dsa.rope.dimension_count, and reject metadata when glm-dsa.expert_used_count
exceeds glm-dsa.expert_count. Use the existing validation error mechanism and
metadata lookup conventions, preserving the current positive-value checks.
- Around line 54-65: Update validate_decoder_layer to explicitly reject any
unsplit blk.N.attn_kv_b.weight tensor, including when split attn_k_b.weight and
attn_v_b.weight tensors are present. Preserve the existing BASE_LAYER_TENSORS
requirements while enforcing that split and unsplit KV-B layouts cannot coexist.

In `@crates/skippy-model-package/src/main.rs`:
- Around line 88-100: Update the ValidateGlmDsaContract handler to retain
printing the validation report, then return a non-zero error when report.valid
is false, matching the validation failure behavior used by
RepairGlmDsaGenerationPolicy. Keep successful validation returning Ok(()) and
preserve the existing JSON output.

---

Outside diff comments:
In `@docs/LAYER_PACKAGE_REPOS.md`:
- Line 1: Align the documentation with the supported model contract by marking
generation.policy.experimental.moe_weighted_down and moe_merged_shared_gate_up
as aspirational or not yet supported wherever they appear in the package
repository docs. Keep selected_row_flash documented as the currently modeled
field, and do not present the unsupported keys as validated manifest fields.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 21a1f1c4-30dd-41a7-b2ef-a8008597a653

📥 Commits

Reviewing files that changed from the base of the PR and between efcae3e and b2181ae.

📒 Files selected for processing (10)
  • crates/model-artifact/src/gguf.rs
  • crates/skippy-model-package/README.md
  • crates/skippy-model-package/src/cli.rs
  • crates/skippy-model-package/src/glm_dsa_contract.rs
  • crates/skippy-model-package/src/glm_dsa_generation_policy.rs
  • crates/skippy-model-package/src/main.rs
  • crates/skippy-model-package/src/preflight.rs
  • docs/LAYER_PACKAGE_REPOS.md
  • docs/specs/GLM_DSA_RUNTIME_CONTRACT.md
  • docs/specs/layer-package-repos.md

Comment thread crates/model-artifact/src/gguf.rs
Comment thread crates/skippy-model-package/README.md Outdated
Comment thread crates/skippy-model-package/README.md
Comment thread crates/skippy-model-package/src/glm_dsa_contract.rs
Comment thread crates/skippy-model-package/src/glm_dsa_contract.rs
Comment thread crates/skippy-model-package/src/glm_dsa_contract.rs
Comment thread crates/skippy-model-package/src/main.rs

@michaelneale michaelneale left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Machine-checkable GLM-DSA package contract validation - the right "fail before runtime, not during lab" instinct, and it's cleanly scoped:

  • New validation logic is self-contained in glm_dsa_contract.rs / glm_dsa_generation_policy.rs; preflight extension is additive.
  • The one shared-surface edit (model-artifact/src/gguf.rs adding kv_lora_rank to GgufCompactMeta) is safe: that struct is in-memory sizing only (derive(Clone, Debug, Default)), not a gossip/wire type, so no mixed-version mesh impact.
  • The KV-cache sizing change is gated behind architecture == "glm-dsa", so it can't perturb sizing for any other model family.
  • CI green incl. clippy, and it carries a real test.

One sequencing note (not a blocker for this PR): it edits skippy-model-package/src/preflight.rs, which #1026 also rewrites - so this should land before #1026 to avoid a conflict.

@i386
i386 merged commit 57ffd59 into main Jul 22, 2026
22 checks passed
@i386
i386 deleted the jd/glm-dsa-package-contract branch July 22, 2026 04:58
michaelneale added a commit that referenced this pull request Jul 22, 2026
…ngram

* origin/main:
  Add GLM DSA correctness trace reporting (#1033)
  Add GLM DSA package contract validation (#1032)
  Add direct quant layer package tooling (#1031)
  Lock split topology placement (#1050)
  fix nightly stability Qwen thinking
  ui(data-mode): migrate legacy harness storage to v2 (#1040)
  fix: Windows Vulkan runtime dependencies (#1046)
  test: validate MI300 runtime selection and placement (#1045)
  fix: support ROCm RDNA APU kernels safely (#1044)
  fix: ROCm GPU enumeration (#1039)
  Document public packaging installation channels
  Fix Windows autoupdate import (#1030)
  Update llama.cpp upstream pin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants