| 172 | |
| 173 | |
| 174 | def build_model_and_enc(model_path): |
| 175 | if not os.path.exists(model_path): # look into ssd |
| 176 | raise FileNotFoundError(f"{model_path} not found!") |
| 177 | print(f"* Building model {model_path}") |
| 178 | |
| 179 | # all hf model |
| 180 | config = AutoConfig.from_pretrained(model_path, trust_remote_code=True) |
| 181 | |
| 182 | enc = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True) |
| 183 | |
| 184 | kwargs = {"torch_dtype": torch.bfloat16, "low_cpu_mem_usage": True} |
| 185 | model = AutoModelForCausalLM.from_pretrained( |
| 186 | model_path, config=config, trust_remote_code=True, **kwargs) |
| 187 | |
| 188 | model.eval() |
| 189 | |
| 190 | return model, enc |
| 191 | |
| 192 | @torch.no_grad() |
| 193 | def apply_clip(module, clip_results): |