Instructions to use agentsea/internlm-xcomposer2-4khd-7b-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use agentsea/internlm-xcomposer2-4khd-7b-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="agentsea/internlm-xcomposer2-4khd-7b-4bit", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("agentsea/internlm-xcomposer2-4khd-7b-4bit", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download ixc_utils.py from agentsea/internlm-xcomposer2-4khd-7b-4bit: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/agentsea/internlm-xcomposer2-4khd-7b-4bit/resolve/3d227c6953e4702b6ae02de0b1b8c183c7534ce1/ixc_utils.py
- Command line
-
hf download hf://agentsea/internlm-xcomposer2-4khd-7b-4bit@3d227c6953e4702b6ae02de0b1b8c183c7534ce1/ixc_utils.py
-
curl -L -o ixc_utils.py https://huggingface.co/agentsea/internlm-xcomposer2-4khd-7b-4bit/resolve/3d227c6953e4702b6ae02de0b1b8c183c7534ce1/ixc_utils.py
1.12 kB
| import torch | |
| import numpy as np | |
| import torchvision | |
| from PIL import Image | |
| from torchvision.transforms.functional import InterpolationMode | |
| import torchvision.transforms as transforms | |
| def padding_336(b): | |
| width, height = b.size | |
| tar = int(np.ceil(height / 336) * 336) | |
| top_padding = int((tar - height)/2) | |
| bottom_padding = tar - height - top_padding | |
| left_padding = 0 | |
| right_padding = 0 | |
| b = transforms.functional.pad(b, [left_padding, top_padding, right_padding, bottom_padding], fill=[255,255,255]) | |
| return b | |
| def HD_transform(img, hd_num=16): | |
| width, height = img.size | |
| trans = False | |
| if width < height: | |
| img = img.transpose(Image.TRANSPOSE) | |
| trans = True | |
| width, height = img.size | |
| ratio = (width/ height) | |
| scale = 1 | |
| while scale*np.ceil(scale/ratio) <= hd_num: | |
| scale += 1 | |
| scale -= 1 | |
| new_w = int(scale * 336) | |
| new_h = int(new_w / ratio) | |
| img = transforms.functional.resize(img, [new_h, new_w],) | |
| img = padding_336(img) | |
| width, height = img.size | |
| if trans: | |
| img = img.transpose(Image.TRANSPOSE) | |
| return img | |