first update to readme
Browse files
README.md
CHANGED
|
@@ -1,3 +1,139 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model: microsoft/Phi-4-multimodal-instruct
|
| 4 |
+
quantization_method: bitsandbytes
|
| 5 |
+
quantization_config:
|
| 6 |
+
load_in_4bit: true
|
| 7 |
+
bnb_4bit_quant_type: nf4
|
| 8 |
+
bnb_4bit_compute_dtype: torch.bfloat16
|
| 9 |
+
bnb_4bit_use_double_quant: true
|
| 10 |
+
tags:
|
| 11 |
+
- phi
|
| 12 |
+
- phi-4
|
| 13 |
+
- phi-4-multimodal
|
| 14 |
+
- multimodal
|
| 15 |
+
- quantized
|
| 16 |
+
- 4bit
|
| 17 |
+
- bitsandbytes
|
| 18 |
+
- bubblspace
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# Bubbl-P4-multimodal-instruct (4-bit Quantized)
|
| 22 |
+
|
| 23 |
+
This repository contains a 4-bit quantized version of the `microsoft/Phi-4-multimodal-instruct` model.
|
| 24 |
+
|
| 25 |
+
Quantization was performed using the `bitsandbytes` library integrated with `transformers`.
|
| 26 |
+
|
| 27 |
+
## Model Description
|
| 28 |
+
|
| 29 |
+
* **Original Model:** [microsoft/Phi-4-multimodal-instruct](https://huggingface.co/microsoft/Phi-4-multimodal-instruct)
|
| 30 |
+
* **Quantization Method:** `bitsandbytes` Post-Training Quantization (PTQ)
|
| 31 |
+
* **Precision:** 4-bit
|
| 32 |
+
* **Quantization Config:**
|
| 33 |
+
* `load_in_4bit=True`
|
| 34 |
+
* `bnb_4bit_quant_type="nf4"` (NormalFloat 4-bit)
|
| 35 |
+
* `bnb_4bit_compute_dtype=torch.bfloat16` (Computation performed in BF16 for compatible GPUs like A100)
|
| 36 |
+
* `bnb_4bit_use_double_quant=True` (Enables nested quantization for potentially more memory savings)
|
| 37 |
+
|
| 38 |
+
This version was created to provide the capabilities of Phi-4-multimodal with a significantly reduced memory footprint, making it suitable for deployment on GPUs with lower VRAM.
|
| 39 |
+
|
| 40 |
+
## Intended Use
|
| 41 |
+
|
| 42 |
+
This quantized model is primarily intended for scenarios where VRAM resources are constrained, but the advanced multimodal reasoning, language understanding, and instruction-following capabilities of `Phi-4-multimodal-instruct` are desired.
|
| 43 |
+
|
| 44 |
+
Refer to the [original model card](https://huggingface.co/microsoft/Phi-4-multimodal-instruct) for the full range of intended uses and capabilities of the base model.
|
| 45 |
+
|
| 46 |
+
## How to Use
|
| 47 |
+
|
| 48 |
+
You can load this 4-bit quantized model directly using the `transformers` library. Ensure you have `bitsandbytes` and `accelerate` installed (`pip install transformers bitsandbytes accelerate torch torchvision pillow soundfile scipy sentencepiece protobuf`).
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from transformers import AutoModelForCausalLM, AutoProcessor
|
| 52 |
+
import torch
|
| 53 |
+
|
| 54 |
+
model_id = "bubblspace/Bubbl-P4-multimodal-instruct"
|
| 55 |
+
|
| 56 |
+
# Load the processor (requires trust_remote_code)
|
| 57 |
+
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
| 58 |
+
|
| 59 |
+
# Load the model with 4-bit quantization enabled
|
| 60 |
+
# The quantization config is loaded automatically from the model's config file
|
| 61 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 62 |
+
model_id,
|
| 63 |
+
trust_remote_code=True, # Essential for Phi-4 models
|
| 64 |
+
load_in_4bit=True, # Explicitly activate 4-bit loading (though config should handle it)
|
| 65 |
+
device_map="auto" # Automatically map model layers to available GPU(s)
|
| 66 |
+
# torch_dtype=torch.bfloat16 # Often not needed here as bnb_4bit_compute_dtype is handled
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
print("4-bit quantized model loaded successfully!")
|
| 70 |
+
|
| 71 |
+
# --- Example: Text Inference ---
|
| 72 |
+
prompt = "<|user|>\nExplain the benefits of model quantization.<|end|>\n<|assistant|>"
|
| 73 |
+
inputs = processor(text=prompt, return_tensors="pt").to(model.device)
|
| 74 |
+
|
| 75 |
+
outputs = model.generate(**inputs, max_new_tokens=150)
|
| 76 |
+
response_text = processor.batch_decode(outputs)[0]
|
| 77 |
+
print(response_text)
|
| 78 |
+
|
| 79 |
+
# --- Example: Image Inference Placeholder ---
|
| 80 |
+
# from PIL import Image
|
| 81 |
+
# import requests
|
| 82 |
+
# url = "your_image_url.jpg"
|
| 83 |
+
# image = Image.open(requests.get(url, stream=True).raw)
|
| 84 |
+
# image_prompt = "<|user|>\n<|image_1|>\nDescribe this image.<|end|>\n<|assistant|>"
|
| 85 |
+
# inputs = processor(text=image_prompt, images=image, return_tensors="pt").to(model.device)
|
| 86 |
+
# outputs = model.generate(**inputs, max_new_tokens=100)
|
| 87 |
+
# response_text = processor.batch_decode(outputs, skip_special_tokens=True)[0]
|
| 88 |
+
# print(response_text)
|
| 89 |
+
|
| 90 |
+
# --- Example: Audio Inference Placeholder ---
|
| 91 |
+
# import soundfile as sf
|
| 92 |
+
# audio_path = "your_audio.wav"
|
| 93 |
+
# audio_array, sampling_rate = sf.read(audio_path)
|
| 94 |
+
# audio_prompt = "<|user|>\n<|audio_1|>\nTranscribe this audio.<|end|>\n<|assistant|>"
|
| 95 |
+
# inputs = processor(text=audio_prompt, audios=[(audio_array, sampling_rate)], return_tensors="pt").to(model.device)
|
| 96 |
+
# # ... generate and decode ...
|
| 97 |
+
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
**Important:** Remember to always pass `trust_remote_code=True` when loading both the processor and the model for Phi-4 architectures.
|
| 101 |
+
|
| 102 |
+
## Hardware Requirements
|
| 103 |
+
|
| 104 |
+
* Requires a CUDA-enabled GPU.
|
| 105 |
+
* The 4-bit quantization significantly reduces VRAM requirements compared to the original BF16 model (approx. 11-12GB). This version should fit comfortably on GPUs with ~10GB VRAM, and potentially less depending on context length and batch size (evaluation recommended).
|
| 106 |
+
* Performance gains (inference speed) compared to the original are most noticeable on GPUs that efficiently handle lower-precision operations (e.g., NVIDIA Ampere, Ada Lovelace series like A100, L4, RTX 30/40xx).
|
| 107 |
+
|
| 108 |
+
## Limitations and Considerations
|
| 109 |
+
|
| 110 |
+
* **Potential Accuracy Impact:** While 4-bit quantization aims to preserve performance, there might be a slight degradation in accuracy compared to the original BF16 model. Users should evaluate the model's performance on their specific tasks to ensure the trade-off is acceptable.
|
| 111 |
+
* **Inference Speed:** Memory usage is significantly reduced. Inference speed may or may not be faster than the original BF16 model; it depends heavily on the hardware, batch size, sequence length, and specific implementation details. Test on your target hardware.
|
| 112 |
+
* **Multimodal Evaluation:** Quantization primarily affects the model weights. Thorough evaluation on specific vision and audio tasks is recommended to confirm performance characteristics for multimodal use cases.
|
| 113 |
+
* **Inherited Limitations:** This model inherits the limitations, biases, and safety considerations of the original `microsoft/Phi-4-multimodal-instruct` model. Please refer to its model card for detailed information on responsible AI practices.
|
| 114 |
+
|
| 115 |
+
## License
|
| 116 |
+
|
| 117 |
+
The model is licensed under the [MIT License](LICENSE), consistent with the original `microsoft/Phi-4-multimodal-instruct` model.
|
| 118 |
+
|
| 119 |
+
## Citation
|
| 120 |
+
|
| 121 |
+
Please cite the original work if you use this model:
|
| 122 |
+
|
| 123 |
+
```bibtex
|
| 124 |
+
@misc{phi4multimodal2025,
|
| 125 |
+
title={Phi-4-multimodal: A Compact Multimodal Model for Recommendation, Recognition, and Reasoning},
|
| 126 |
+
author={Microsoft},
|
| 127 |
+
year={2025},
|
| 128 |
+
eprint={2503.01743},
|
| 129 |
+
archivePrefix={arXiv},
|
| 130 |
+
primaryClass={cs.CL}
|
| 131 |
+
}
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
Additionally, if you use this specific 4-bit quantized version, please acknowledge **Bubblspace** ([bubblspace.com](https://bubblspace.com)) and **AIEDX** ([aiedx.com](https://aiedx.com)) for providing this quantized model. You could add a note such as:
|
| 137 |
+
|
| 138 |
+
> *"We used the 4-bit quantized version of Phi-4-multimodal-instruct provided by Bubblspace/AIEDX, available at huggingface.co/bubblspace/Bubbl-P4-multimodal-instruct."*
|
| 139 |
+
|