Instructions to use Hon-Wong/VoRA-7B-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Hon-Wong/VoRA-7B-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Hon-Wong/VoRA-7B-Base", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Hon-Wong/VoRA-7B-Base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Hon-Wong/VoRA-7B-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Hon-Wong/VoRA-7B-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Hon-Wong/VoRA-7B-Base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Hon-Wong/VoRA-7B-Base
- SGLang
How to use Hon-Wong/VoRA-7B-Base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Hon-Wong/VoRA-7B-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Hon-Wong/VoRA-7B-Base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Hon-Wong/VoRA-7B-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Hon-Wong/VoRA-7B-Base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Hon-Wong/VoRA-7B-Base with Docker Model Runner:
docker model run hf.co/Hon-Wong/VoRA-7B-Base
| import torch | |
| import types | |
| import math | |
| from torch import nn | |
| import torch.nn.functional as F | |
| QWEN2_TARGET_MODULES = [ | |
| "self_attn.q_proj", | |
| "self_attn.k_proj", | |
| "self_attn.v_proj", | |
| "self_attn.o_proj", | |
| "mlp.up_proj", | |
| "mlp.gate_proj", | |
| "mlp.down_proj", | |
| ] | |
| class LoRALayer(nn.Linear): | |
| def __init__( | |
| self, | |
| in_features: int, | |
| out_features: int, | |
| r: int = 1024, | |
| **kwargs | |
| ): | |
| nn.Linear.__init__(self, in_features, out_features) | |
| if r < 0: | |
| self.forward = self.naive_forward | |
| else: | |
| # we elimate lora_alpha here bc we find it unnecessary in VoRA | |
| self.lora_A = nn.Linear(in_features, r, bias=False) | |
| self.lora_B = nn.Linear(r, out_features, bias=False) | |
| nn.init.kaiming_uniform_(self.lora_A.weight, a=math.sqrt(5)) | |
| nn.init.zeros_(self.lora_B.weight) | |
| def forward(self, x: torch.Tensor): | |
| intermediate = F.linear(x, self.weight, bias=self.bias) | |
| result = intermediate + self.lora_B(self.lora_A(x)) | |
| return result | |
| def naive_forward(self, x: torch.Tensor): | |
| return F.linear(x, self.weight, bias=self.bias) | |
| def _get_submodules(self, key): | |
| parent = self.get_submodule(".".join(key.split(".")[:-1])) | |
| target_name = key.split(".")[-1] | |
| target = self.get_submodule(key) | |
| return parent, target, target_name | |
| def _find_and_replace(self, lora_params): | |
| target_modules = lora_params["target_modules"] | |
| for llm_module_name in target_modules: | |
| parent, target, target_name = self._get_submodules(llm_module_name) | |
| vora_layer = LoRALayer( | |
| target.in_features, | |
| target.out_features, | |
| **lora_params | |
| ) | |
| self._replace_module(parent, target_name, vora_layer, target) | |
| def _replace_module(self, parent_module, child_name, new_module, old_module): | |
| setattr(parent_module, child_name, new_module) | |
| new_module.weight = old_module.weight | |
| if old_module.bias is not None: | |
| new_module.bias = old_module.bias | |
| if getattr(old_module, "state", None) is not None: | |
| new_module.state = old_module.state | |
| new_module.to(old_module.weight.device) | |
| def apply_lora(llm, lora_params={"layers": "all", "r": 1024, "target_modules": QWEN2_TARGET_MODULES}): | |
| llm_num_layers = llm.config.num_hidden_layers | |
| total_layers = lora_params.get("layers", "all") | |
| # -------------------- validation check --------------------- | |
| if isinstance(total_layers, str): | |
| if total_layers.lower() == "all": | |
| total_layers = list(range(llm_num_layers)) | |
| else: | |
| assert isinstance(total_layers, int), "total_layers must be an integer or 'all'" | |
| total_layers = list(range(total_layers)) | |
| # -------------------- validation check --------------------- | |
| # -------------------- replace llm layers --------------------- | |
| for i in total_layers: | |
| llm_layer = llm.model.layers[i] | |
| llm_layer._get_submodules = types.MethodType(_get_submodules, llm_layer) | |
| llm_layer._find_and_replace = types.MethodType(_find_and_replace, llm_layer) | |
| llm_layer._replace_module = types.MethodType(_replace_module, llm_layer) | |
| llm_layer._find_and_replace(lora_params) | |