Download preload_models.py from nexusbert/Heart: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/nexusbert/Heart/resolve/main/preload_models.py
- Command line
-
hf download hf://spaces/nexusbert/Heart/preload_models.py
-
curl -L -o preload_models.py https://huggingface.co/spaces/nexusbert/Heart/resolve/main/preload_models.py
1.22 kB
| import torch | |
| from transformers import AutoProcessor, AutoModelForMultimodalLM, BitsAndBytesConfig | |
| DTYPE = torch.float16 if torch.cuda.is_available() else torch.float32 | |
| def preload(): | |
| print("Preloading models to disk...") | |
| quant_config = BitsAndBytesConfig( | |
| load_in_4bit=True, | |
| bnb_4bit_compute_dtype=DTYPE, | |
| bnb_4bit_quant_type="nf4", | |
| bnb_4bit_use_double_quant=True, | |
| ) | |
| print("Preloading GemmaECG-Vision...") | |
| AutoProcessor.from_pretrained("yasserrmd/GemmaECG-Vision") | |
| AutoModelForMultimodalLM.from_pretrained( | |
| "yasserrmd/GemmaECG-Vision", | |
| device_map="cpu", # Use CPU for build time to avoid needing GPU in Docker build | |
| quantization_config=quant_config, | |
| low_cpu_mem_usage=True, | |
| ) | |
| print("Preloading Google TabFM...") | |
| try: | |
| from tabfm import tabfm_v1_0_0_pytorch as tabfm_v1_0_0 | |
| tabfm_v1_0_0.load(model_type="classification") | |
| except Exception as e: | |
| print(f"Warning: Could not preload TabFM model: {e}") | |
| print("Groq is used for reasoning/report synthesis and does not require local model preload.") | |
| print("All models preloaded successfully.") | |
| if __name__ == "__main__": | |
| preload() | |