Skip to content

Feature Request: Add "trust_remote_code support" to 'convert_hf_to_gguf.py' for compatibility with modern HF models #12610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
joeyama opened this issue Mar 27, 2025 · 1 comment
Labels
enhancement New feature or request stale

Comments

@joeyama
Copy link

joeyama commented Mar 27, 2025

Prerequisites

  • I am running the latest code. Mention the version if possible as well.
  • I carefully followed the README.md.
  • I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • I reviewed the Discussions, and have a new and useful enhancement to share.

Feature Description

Summary

The current convert_hf_to_gguf.py script fails to convert HuggingFace models that require trust_remote_code=True, especially those using custom tokenizers or architectures (e.g., TikTokenTokenizer). This results in runtime errors or input prompts that break automation and scripting workflows.

Adding support for trust_remote_code (via CLI flag or built-in toggle) would enable full compatibility with a growing set of modern models.


🔥 Encountered Issues

During conversion of huihui-ai/Moonlight-16B-A3B-Instruct-abliterated, the following blockers were hit:

  1. Broken tokenizer_config.json

    • Trailing comma → JSONDecodeError
    • Manual fix required
  2. Script lacks support for trust_remote_code=True

    • Models using TikTokenTokenizer trigger:
      ValueError: Please pass trust_remote_code=True
      
    • Prompt appears even when run in non-interactive mode
    • No --trust-remote-code CLI flag exists
  3. Script attempts .vocab on TikTokenTokenizer

    • Raises:
      AttributeError: 'TikTokenTokenizer' object has no attribute 'vocab'
      
    • Workaround: use tokenizer.model.n_vocab or hardcoded value

🧠 Suggested Fixes

(Flexible depending on preference)

  • ✅ Add CLI flag: --trust-remote-code
  • ✅ Pass the flag to AutoTokenizer.from_pretrained() and AutoModelForCausalLM.from_pretrained()
  • ✅ Gracefully handle vocab fallback for tokenizers missing .vocab

Optional:

  • ❓ Auto-enable trust_remote_code if tokenizer_class is custom?
  • ❓ Add an example or mention this behavior in README or docs/gguf.md

🧪 Repro Steps

git clone https://huggingface.co/huihui-ai/Moonlight-16B-A3B-Instruct-abliterated
./convert_hf_to_gguf.py --verbose  --outfile moonlight.gguf --outtype bf16 huihui-ai/Moonlight-16B-A3B-Instruct-abliterated
# fails with prompt + crashes if not patched

✅ Workaround (What I Did)

  • Manually patched:
    AutoTokenizer.from_pretrained(..., trust_remote_code=True)
  • Replaced .vocab call with tokenizer.model.n_vocab
  • Then conversion succeeded

🙏 Why This Matters

Many newer models are starting to:

  • Use custom tokenizers (TikToken, JinjaTokenizer, etc.)
  • Require remote code execution
  • Break current conversion pipelines

Fixing this once will unlock dozens of models for GGUF and llama.cpp.

Happy to PR this if helpful. Thanks again for all the work — your tooling is incredible.

Motivation

Motivation

Support for trust_remote_code=True is increasingly important as more HuggingFace models rely on custom tokenizers or architectures. Without it, convert_hf_to_gguf.py cannot load or convert these models, blocking compatibility with llama.cpp.

Possible Implementation

No response

@joeyama joeyama added the enhancement New feature or request label Mar 27, 2025
@github-actions github-actions bot added the stale label Apr 27, 2025
Copy link
Contributor

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

1 participant