Instructions to use chandar-lab/NeoBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use chandar-lab/NeoBERT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="chandar-lab/NeoBERT", trust_remote_code=True)# Load model directly from transformers import AutoModelForMaskedLM model = AutoModelForMaskedLM.from_pretrained("chandar-lab/NeoBERT", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
Fix NaNs in model output
#14
by tlo4 - opened
model.py
CHANGED
|
@@ -207,7 +207,16 @@ class NeoBERTPreTrainedModel(PreTrainedModel):
|
|
| 207 |
module.weight.data.uniform_(-self.config.decoder_init_range, self.config.decoder_init_range)
|
| 208 |
elif isinstance(module, nn.Embedding):
|
| 209 |
module.weight.data.uniform_(-self.config.embedding_init_range, self.config.embedding_init_range)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
class NeoBERT(NeoBERTPreTrainedModel):
|
| 213 |
config_class = NeoBERTConfig
|
|
|
|
| 207 |
module.weight.data.uniform_(-self.config.decoder_init_range, self.config.decoder_init_range)
|
| 208 |
elif isinstance(module, nn.Embedding):
|
| 209 |
module.weight.data.uniform_(-self.config.embedding_init_range, self.config.embedding_init_range)
|
| 210 |
+
elif isinstance(module, NeoBERT):
|
| 211 |
+
freqs = precompute_freqs_cis(
|
| 212 |
+
self.config.hidden_size // self.config.num_attention_heads,
|
| 213 |
+
self.config.max_length
|
| 214 |
+
)
|
| 215 |
|
| 216 |
+
if module.freqs_cis.device.type == "meta":
|
| 217 |
+
module.freqs_cis = freqs.to(module.freqs_cis.device)
|
| 218 |
+
else:
|
| 219 |
+
module.freqs_cis.copy_(freqs.to(device=module.freqs_cis.device, dtype=module.freqs_cis.dtype))
|
| 220 |
|
| 221 |
class NeoBERT(NeoBERTPreTrainedModel):
|
| 222 |
config_class = NeoBERTConfig
|