[BUG]: export_gguf.py crashes with unhandled tracebacks on missing inputs and allows overwriting source checkpoint

Aperta
#351 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@AdityasagarR123 ci sta già lavorando.

Dal 18/11/2026.

  • #352 di @AdityasagarR123 — aperta
  • #363 di @ayush-shft-ctrl — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python, pytorch

Direzione di ricerca

Start by comparing simple/export_gguf.py with the input validation and error handling in simple/export_safetensors.py, then inspect tests/simple/test_export_gguf.py if present. The issue specifies missing input, invalid checkpoint, overwrite, and vocabulary validation cases; done means those cases exit cleanly without tracebacks. A linked open pull request is already addressing this work.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Description

In simple/export_safetensors.py, input validation and error handling were hardened (issue #295) to validate file existence before reading, report invalid checkpoints cleanly, and refuse to overwrite the source checkpoint.

However, simple/export_gguf.py currently performs no input validation in main():

run = Path(a.run)
cfg = json.loads((run / "recipe.json").read_text(encoding="utf-8"))["model"]
weights = run / f"{a.model}-model.pt"
sd = torch.load(weights, map_location="cpu", weights_only=True)
tok = json.loads(Path(a.tokenizer).read_text(encoding="utf-8"))["model"]
vocab = sorted(tok["vocab"].items(), key=lambda kv: kv[1])
assert [i for _, i in vocab] == list(range(len(vocab))), "tokenizer ids must be contiguous"
assert len(CONTROLS) + len(vocab) == cfg["vocab_size"], "vocabulary size differs from the recipe"

This leads to several failure modes:

  1. Missing recipe.json: If --run does not contain recipe.json, it raises an unhandled FileNotFoundError traceback.
  2. Missing or invalid checkpoint: If {model}-model.pt is missing, torch.load crashes with FileNotFoundError. If corrupted, it produces an unhandled traceback.
  3. Missing tokenizer: If --tokenizer points to a nonexistent file, read_text raises an unhandled FileNotFoundError traceback.
  4. Source checkpoint overwrite: If --out points to the input checkpoint path (e.g. --out RUN/conversation-model.pt), the script overwrites the PyTorch checkpoint with GGUF bytes, destroying the source model weights.
  5. Raw AssertionError: Vocabulary size and contiguous ID assertions raise AssertionError tracebacks instead of clean error messages.
Steps to Reproduce
  1. Run export_gguf.py with a missing run directory or missing checkpoint:

    python simple/export_gguf.py --run nonexistent --tokenizer tokenizer.json --out out.gguf
    

    Output:

    FileNotFoundError: [Errno 2] No such file or directory: 'nonexistent/recipe.json'
    
  2. Run export_gguf.py with --out pointing to the input checkpoint:

    python simple/export_gguf.py --run RUN --tokenizer PREP/tokenizer/tokenizer.json --out RUN/conversation-model.pt
    

    The source .pt model checkpoint is overwritten and corrupted.

Expected Behavior

Align error handling with simple/export_safetensors.py:

  • Validate that recipe.json, weights, and tokenizer exist before reading, exiting cleanly with sys.exit(...) if missing.
  • Catch corrupted checkpoint files cleanly: sys.exit(f"source checkpoint {weights} is invalid: {exc}").
  • Reject --out when it resolves to the source checkpoint: p.error("--out must not overwrite the source checkpoint").
  • Replace raw assert statements with sys.exit(...) for vocabulary validation.
  • Add unit tests in tests/simple/test_export_gguf.py verifying that missing inputs, invalid checkpoints, and overwrite attempts exit cleanly without tracebacks.

@ryoari Could you please assign this to me ? I can prepare a focused PR implementing these checks along with unit tests.

Update

Implemented in #352. Beyond the list above:

  • The GGUF is written to a temporary file and renamed into place only when complete, so a failed export never leaves a broken .gguf.
  • The recipe's model fields, the checkpoint's tensors and the tokenizer's vocab and merges are all checked before anything is written.
  • The overwrite guard also catches the source reached through another path or a hard link.
Lingua principale
Python
Stelle
26
Fork
64
Merge medio
2g 11h
PR unite (30g)
71

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AOSSIE-Org/OpenVerifiableLLM

Tutte le issue di AOSSIE-Org/OpenVerifiableLLM

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.