AnswerDotAI / AnswerDotAI/ModernBERT

Pretraining with FlexBert but can't export to HF

Open
#234 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.7k
Forks
145
PR merge metrics
No merged PRs in 30d

Description

Hi @warner-benjamin and team,
Thank you for your fantastic work on ModernBERT and FlexBert!

I’ve trained a FlexBert model using your codebase and I’m now trying to convert it to Hugging Face Transformers format for easier sharing and downstream use. I found the convert_to_hf.py script referenced in some previous issues and used it, along with the model definitions from [this YAML](https://github.com/AnswerDotAI/ModernBERT/blob/pretraining_documentation/yamls/modernbert/modernbert-base-pretrain.yaml).

The model loads correctly with AutoModel and AutoTokenizer, but when I run a forward pass, the outputs are all NaN.
```
from transformers import AutoModel, AutoConfig

model_path = ""
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModel.from_pretrained(model_path)
inputs = tokenizer("Hello world", return_tensors="pt")
with torch.no_grad():
outputs = test_model(**inputs) # <- returns all NaN
```

Do you have any advice or best practices for converting models to HF format, or tips on what might be causing this issue? Any guidance would be greatly appreciated!

Thanks in advance!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the conversion with convert_to_hf.py, the FlexBert definitions from the linked modernbert-base-pretrain.yaml, and a short AutoModel forward pass. Compare the converted model's outputs with the original model and inspect where NaN values first appear. Done means identifying the conversion cause and producing an HF-format model whose forward pass returns valid outputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.