XLMRobertaLarge adapted from Huggingface.
(pretrained=False,
return_tokenizer=False,
device='cpu',
**kwargs)
| 148 | |
| 149 | |
| 150 | def xlm_roberta_large(pretrained=False, |
| 151 | return_tokenizer=False, |
| 152 | device='cpu', |
| 153 | **kwargs): |
| 154 | """ |
| 155 | XLMRobertaLarge adapted from Huggingface. |
| 156 | """ |
| 157 | # params |
| 158 | cfg = dict( |
| 159 | vocab_size=250002, |
| 160 | max_seq_len=514, |
| 161 | type_size=1, |
| 162 | pad_id=1, |
| 163 | dim=1024, |
| 164 | num_heads=16, |
| 165 | num_layers=24, |
| 166 | post_norm=True, |
| 167 | dropout=0.1, |
| 168 | eps=1e-5) |
| 169 | cfg.update(**kwargs) |
| 170 | |
| 171 | # init model |
| 172 | if pretrained: |
| 173 | from sora import DOWNLOAD_TO_CACHE |
| 174 | |
| 175 | # init a meta model |
| 176 | with torch.device('meta'): |
| 177 | model = XLMRoberta(**cfg) |
| 178 | |
| 179 | # load checkpoint |
| 180 | model.load_state_dict( |
| 181 | torch.load( |
| 182 | DOWNLOAD_TO_CACHE('models/xlm_roberta/xlm_roberta_large.pth'), |
| 183 | map_location=device), |
| 184 | assign=True) |
| 185 | else: |
| 186 | # init a model on device |
| 187 | with torch.device(device): |
| 188 | model = XLMRoberta(**cfg) |
| 189 | |
| 190 | # init tokenizer |
| 191 | if return_tokenizer: |
| 192 | from sora.data import HuggingfaceTokenizer |
| 193 | tokenizer = HuggingfaceTokenizer( |
| 194 | name='xlm-roberta-large', |
| 195 | seq_len=model.text_len, |
| 196 | clean='whitespace') |
| 197 | return model, tokenizer |
| 198 | else: |
| 199 | return model |
| 200 | |
| 201 | |
| 202 |
nothing calls this directly
no test coverage detected