Instructions to use 5CD-AI/ColVintern-1B-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use 5CD-AI/ColVintern-1B-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="5CD-AI/ColVintern-1B-v1", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("5CD-AI/ColVintern-1B-v1", trust_remote_code=True, device_map="auto") - ColPali
How to use 5CD-AI/ColVintern-1B-v1 with ColPali:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download torch_utils.py from 5CD-AI/ColVintern-1B-v1: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/5CD-AI/ColVintern-1B-v1/resolve/5030b76b6943b0097edb83c27862850f45b472ee/torch_utils.py
- Command line
-
hf download hf://5CD-AI/ColVintern-1B-v1@5030b76b6943b0097edb83c27862850f45b472ee/torch_utils.py
-
curl -L -o torch_utils.py https://huggingface.co/5CD-AI/ColVintern-1B-v1/resolve/5030b76b6943b0097edb83c27862850f45b472ee/torch_utils.py
1.15 kB
| import gc | |
| import logging | |
| from typing import List, TypeVar | |
| import torch | |
| from torch.utils.data import Dataset | |
| logger = logging.getLogger(__name__) | |
| T = TypeVar("T") | |
| def get_torch_device(device: str = "auto") -> str: | |
| """ | |
| Returns the device (string) to be used by PyTorch. | |
| `device` arg defaults to "auto" which will use: | |
| - "cuda:0" if available | |
| - else "mps" if available | |
| - else "cpu". | |
| """ | |
| if device == "auto": | |
| if torch.cuda.is_available(): | |
| device = "cuda:0" | |
| elif torch.backends.mps.is_available(): # for Apple Silicon | |
| device = "mps" | |
| else: | |
| device = "cpu" | |
| logger.info(f"Using device: {device}") | |
| return device | |
| def tear_down_torch(): | |
| """ | |
| Teardown for PyTorch. | |
| Clears GPU cache for both CUDA and MPS. | |
| """ | |
| gc.collect() | |
| torch.cuda.empty_cache() | |
| torch.mps.empty_cache() | |
| class ListDataset(Dataset[T]): | |
| def __init__(self, elements: List[T]): | |
| self.elements = elements | |
| def __len__(self) -> int: | |
| return len(self.elements) | |
| def __getitem__(self, idx: int) -> T: | |
| return self.elements[idx] | |