Skip to content

GPT-2 GGUF export missing hidden_dim metadata (roundtrip fails) #236

@noahgift

Description

@noahgift

Bug Report

Source: tiny-model-ground-truth parity checker (0/59 passing)
Severity: High — blocks GPT-2 GGUF roundtrip
Related: Follow-up to #233 (GPT-2 architecture support)

Description

When reimporting a GPT-2 GGUF file (apr import model.gguf), the contract enforcement fails because hidden_dim=0:

CONTRACT ENFORCEMENT FAILED: Missing vocab_size (50257) or hidden_dim (0).
Cannot validate tensor layouts without model config. This GGUF file may be malformed.

The GGUF export for GPT-2 writes vocab_size but not hidden_dim (or writes it as 0).

Error Output

[PMAT-222] Auto-detected architecture: Gpt2
[PMAT-224] WARNING: Architecture 'GPT-2' has not been verified for inference.

error: CONTRACT ENFORCEMENT FAILED: Missing vocab_size (50257) or hidden_dim (0).
Cannot validate tensor layouts without model config.

Root Cause

The GGUF export path (apr export --format gguf) doesn't write the correct metadata key for GPT-2's hidden dimension. The GGUF metadata writer likely uses an architecture-specific key like gpt2.embedding_length that either:

  1. Isn't being written during export, or
  2. Isn't being read back during reimport

This may also be related to the hidden_dim=64 bug (see companion issue) — if the APR file itself stores 64 as hidden_dim, the GGUF export might be writing 64 or 0.

Reproduction

cd tiny-model-ground-truth
apr import models/gpt2-124m-int4.gguf -o models/gpt2-roundtrip.apr
# → CONTRACT ENFORCEMENT FAILED: hidden_dim (0)

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions