dmis-lab commited on
Commit
671a38c
·
verified ·
1 Parent(s): 6346c25

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -8
README.md CHANGED
@@ -47,17 +47,16 @@ For more information about UltraBERT, please check out [our paper](https://arxiv
47
 
48
  ## 🚀 Usage
49
 
50
- The model needs `transformers >= 5` (tested with 5.16.1) and `trust_remote_code=True`. FlashAttention 2 is recommended for long inputs; SDPA and eager attention are also supported.
51
 
52
  ```python
53
  import torch
54
  from transformers import AutoModelForMaskedLM, AutoTokenizer
55
 
56
  model_id = "dmis-lab/UltraBERT-380M"
57
- tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
58
  model = AutoModelForMaskedLM.from_pretrained(
59
  model_id,
60
- trust_remote_code=True,
61
  dtype=torch.bfloat16,
62
  attn_implementation="flash_attention_2", # or "sdpa"
63
  device_map="cuda",
@@ -80,15 +79,14 @@ The checkpoint loads into the usual task classes:
80
  from transformers import AutoModelForSequenceClassification
81
 
82
  model = AutoModelForSequenceClassification.from_pretrained(
83
- "dmis-lab/UltraBERT-380M", num_labels=2, trust_remote_code=True
84
  )
85
  ```
86
 
87
  We recommend starting from the settings used in the paper. For classification: AdamW (β1 0.9, β2 0.98, ε 1e-6), weight decay 0.1, a linear schedule with 5% warm-up, and a learning rate swept over {5e-6,8e-6,1e-5,3e-5,5e-5,8e-5}. For dense retrieval: mean pooling with a contrastive loss and a wider learning-rate sweep of {1e-5,3e-5,5e-5,8e-5,1e-4,2e-4,3e-4,5e-4,8e-4,1e-3}.
88
 
89
  > [!WARNING]
90
- > 💡 **Note**: UltraBERT consistently prefers lower learning rates than other encoders, by up to 10x. For example, the best learning rates for UltraBERT-150M and UltraBERT-380M are 5e-5 and 3e-5, respectively, whereas other encoders typically prefer 3e-4 to 5e-4.
91
-
92
 
93
  ## 📊 Evaluation
94
 
@@ -159,8 +157,9 @@ UltraBERT is a pre-norm Transformer encoder with RoPE, SwiGLU feed-forward layer
159
  ```python
160
  from huggingface_hub import hf_hub_download
161
 
162
- head_path = hf_hub_download("dmis-lab/UltraBERT-380M", "head_50%.pth")
163
- model.load_state_dict(torch.load(head_path), strict=False)
 
164
  ```
165
 
166
  ## ⚙️ Pre-Training
 
47
 
48
  ## 🚀 Usage
49
 
50
+ UltraBERT is supported natively in `transformers >= 5.20`. On earlier 5.x versions (tested with 5.16.1), pass `trust_remote_code=True`. FlashAttention 2 is recommended for long inputs; SDPA and eager attention are also supported.
51
 
52
  ```python
53
  import torch
54
  from transformers import AutoModelForMaskedLM, AutoTokenizer
55
 
56
  model_id = "dmis-lab/UltraBERT-380M"
57
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
58
  model = AutoModelForMaskedLM.from_pretrained(
59
  model_id,
 
60
  dtype=torch.bfloat16,
61
  attn_implementation="flash_attention_2", # or "sdpa"
62
  device_map="cuda",
 
79
  from transformers import AutoModelForSequenceClassification
80
 
81
  model = AutoModelForSequenceClassification.from_pretrained(
82
+ "dmis-lab/UltraBERT-380M", num_labels=2
83
  )
84
  ```
85
 
86
  We recommend starting from the settings used in the paper. For classification: AdamW (β1 0.9, β2 0.98, ε 1e-6), weight decay 0.1, a linear schedule with 5% warm-up, and a learning rate swept over {5e-6,8e-6,1e-5,3e-5,5e-5,8e-5}. For dense retrieval: mean pooling with a contrastive loss and a wider learning-rate sweep of {1e-5,3e-5,5e-5,8e-5,1e-4,2e-4,3e-4,5e-4,8e-4,1e-3}.
87
 
88
  > [!WARNING]
89
+ > 💡 **Note**: UltraBERT consistently prefers lower learning rates than other encoders, by up to 10x. For example, on MNLI the best learning rates for UltraBERT-150M and UltraBERT-380M are 1e-5 and 8e-6, respectively, whereas other encoders typically prefer 3e-5 to 5e-5. For dense retrieval, they are 5e-5 and 3e-5, whereas other encoders typically prefer 3e-4 to 5e-4.
 
90
 
91
  ## 📊 Evaluation
92
 
 
157
  ```python
158
  from huggingface_hub import hf_hub_download
159
 
160
+ state = torch.load(hf_hub_download("dmis-lab/UltraBERT-380M", "head_50%.pth"))
161
+ state["head.decoder.weight"] = state.pop("cls.weight") # skip with trust_remote_code=True
162
+ model.load_state_dict(state, strict=False)
163
  ```
164
 
165
  ## ⚙️ Pre-Training