Feature Extraction
Transformers
Safetensors
llama_bidirec
mergekit
Merge
custom_code
text-embeddings-inference
8-bit precision
Instructions to use KwangHwi/quantization with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use KwangHwi/quantization with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="KwangHwi/quantization", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("KwangHwi/quantization", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | |
| # SPDX-License-Identifier: Apache-2.0. | |
| from torch import Tensor | |
| import torch | |
| def pool(last_hidden_states: Tensor, attention_mask: Tensor, pool_type: str) -> Tensor: | |
| last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0) | |
| if pool_type == "avg": | |
| emb = last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None] | |
| elif pool_type == "weighted_avg": | |
| emb = last_hidden.sum(dim=1) | |
| elif pool_type == "cls": | |
| emb = last_hidden[:, 0] | |
| elif pool_type == "last": | |
| left_padding = attention_mask[:, -1].sum() == attention_mask.shape[0] | |
| if left_padding: | |
| emb = last_hidden[:, -1] | |
| else: | |
| sequence_lengths = attention_mask.sum(dim=1) - 1 | |
| batch_size = last_hidden.shape[0] | |
| emb = last_hidden[ | |
| torch.arange(batch_size, device=last_hidden.device), sequence_lengths | |
| ] | |
| else: | |
| raise ValueError(f"pool_type {pool_type} not supported") | |
| return emb | |