Feature Extraction
Transformers
Safetensors
qwen3_5
image-text-to-text
multimodal-embedding
retrieval
evaluation
custom_code
Instructions to use woooooz/WeMM-Embedding-9B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use woooooz/WeMM-Embedding-9B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="woooooz/WeMM-Embedding-9B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("woooooz/WeMM-Embedding-9B", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("woooooz/WeMM-Embedding-9B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download evaluation/vendor/transformers/quantizers/quantizer_bitnet.py from woooooz/WeMM-Embedding-9B: direct link, hf CLI and curl.
- Browser
- Download file 4.53 kB
-
https://huggingface.co/woooooz/WeMM-Embedding-9B/resolve/main/evaluation/vendor/transformers/quantizers/quantizer_bitnet.py
- Command line
-
hf download hf://woooooz/WeMM-Embedding-9B/evaluation/vendor/transformers/quantizers/quantizer_bitnet.py
-
curl -L -o quantizer_bitnet.py https://huggingface.co/woooooz/WeMM-Embedding-9B/resolve/main/evaluation/vendor/transformers/quantizers/quantizer_bitnet.py
4.53 kB
| # Copyright 2024 The HuggingFace Inc. team. All rights reserved. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| from typing import TYPE_CHECKING | |
| from .base import HfQuantizer | |
| if TYPE_CHECKING: | |
| from ..modeling_utils import PreTrainedModel | |
| from ..utils.quantization_config import BitNetQuantConfig | |
| from ..utils import is_accelerate_available, is_torch_available, logging | |
| if is_torch_available(): | |
| import torch | |
| logger = logging.get_logger(__name__) | |
| class BitNetHfQuantizer(HfQuantizer): | |
| """ | |
| 1.58-bit quantization from BitNet quantization method: | |
| Before loading: it converts the linear layers into BitLinear layers during loading. | |
| Check out the paper introducing this method: https://huggingface.co/papers/2402.17764 | |
| """ | |
| requires_calibration = True | |
| quantization_config: "BitNetQuantConfig" | |
| def __init__(self, quantization_config, **kwargs): | |
| super().__init__(quantization_config, **kwargs) | |
| def validate_environment(self, *args, **kwargs): | |
| if not is_accelerate_available(): | |
| raise ImportError("Loading a BitNet quantized model requires accelerate (`pip install accelerate`)") | |
| if not torch.cuda.is_available(): | |
| logger.warning_once( | |
| "You don't have a GPU available to load the model, the inference will be slow because of weight unpacking" | |
| ) | |
| return | |
| device_map = kwargs.get("device_map") | |
| if device_map is None: | |
| logger.warning_once( | |
| "You have loaded a BitNet model on CPU and have a CUDA device available, make sure to set " | |
| "your model on a GPU device in order to run your model." | |
| ) | |
| elif isinstance(device_map, dict): | |
| if len(device_map) > 1 and "cpu" in device_map.values() or "disk" in device_map.values(): | |
| raise ValueError( | |
| "You are attempting to load a BitNet model with a device_map that contains a CPU or disk device." | |
| "This is not supported. Please remove the CPU or disk device from the device_map." | |
| ) | |
| def _process_model_before_weight_loading( | |
| self, | |
| model: "PreTrainedModel", | |
| **kwargs, | |
| ): | |
| from ..integrations import replace_with_bitnet_linear | |
| self.modules_to_not_convert = self.get_modules_to_not_convert( | |
| model, self.quantization_config.modules_to_not_convert, model._keep_in_fp32_modules | |
| ) | |
| model = replace_with_bitnet_linear( | |
| model, | |
| modules_to_not_convert=self.modules_to_not_convert, | |
| quantization_config=self.quantization_config, | |
| ) | |
| def adjust_max_memory(self, max_memory: dict[str, int | str]) -> dict[str, int | str]: | |
| max_memory = {key: val * 0.90 for key, val in max_memory.items()} | |
| return max_memory | |
| def is_serializable(self): | |
| return True | |
| def is_trainable(self) -> bool: | |
| return ( | |
| self.quantization_config.linear_class == "autobitlinear" | |
| and self.quantization_config.quantization_mode == "online" | |
| ) | |
| def is_qat_trainable(self) -> bool: | |
| """Flag indicating whether the quantized model can carry out quantization aware training""" | |
| return ( | |
| self.quantization_config.linear_class == "autobitlinear" | |
| and self.quantization_config.quantization_mode == "online" | |
| ) | |
| def get_weight_conversions(self): | |
| from ..core_model_loading import WeightConverter | |
| from ..integrations.bitnet import BitNetDeserialize | |
| if ( | |
| self.quantization_config.linear_class == "autobitlinear" | |
| and self.quantization_config.quantization_mode == "offline" | |
| ): | |
| return [ | |
| WeightConverter( | |
| source_patterns=["weight"], | |
| target_patterns=["weight"], | |
| operations=[BitNetDeserialize(self)], | |
| ) | |
| ] | |
| return [] | |