Use as the abstractmethod, load corresponding HF model. Subclass must implement this method!
(cls, model_dir: str, load_model_on_cpu: bool,
dtype: torch.dtype)
| 129 | |
| 130 | @classmethod |
| 131 | def load_hf_bert(cls, model_dir: str, load_model_on_cpu: bool, |
| 132 | dtype: torch.dtype): |
| 133 | """ |
| 134 | Use as the abstractmethod, load corresponding HF model. |
| 135 | Subclass must implement this method! |
| 136 | """ |
| 137 | |
| 138 | assert cls.__name__ != "BertBase", f"Never call from BertBase class!" |
| 139 | |
| 140 | if cls.__name__ == "BertModel": |
| 141 | return load_hf_bert_base(model_dir, load_model_on_cpu, dtype) |
| 142 | elif cls.__name__ == "BertForQuestionAnswering": |
| 143 | return load_hf_bert_qa(model_dir, load_model_on_cpu, dtype) |
| 144 | elif cls.__name__ == "BertForSequenceClassification": |
| 145 | return load_hf_bert_cls(model_dir, load_model_on_cpu, dtype) |
| 146 | else: |
| 147 | assert False, f"Unknown class {cls.__name__}!" |
| 148 | |
| 149 | @classmethod |
| 150 | def from_hugging_face( |
no test coverage detected