Instructions to use Mrw33554432/bitLinear-phi-1.5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Mrw33554432/bitLinear-phi-1.5 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Mrw33554432/bitLinear-phi-1.5", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Mrw33554432/bitLinear-phi-1.5", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("Mrw33554432/bitLinear-phi-1.5", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Mrw33554432/bitLinear-phi-1.5 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Mrw33554432/bitLinear-phi-1.5" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Mrw33554432/bitLinear-phi-1.5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Mrw33554432/bitLinear-phi-1.5
- SGLang
How to use Mrw33554432/bitLinear-phi-1.5 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 "Mrw33554432/bitLinear-phi-1.5" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Mrw33554432/bitLinear-phi-1.5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "Mrw33554432/bitLinear-phi-1.5" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Mrw33554432/bitLinear-phi-1.5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Mrw33554432/bitLinear-phi-1.5 with Docker Model Runner:
docker model run hf.co/Mrw33554432/bitLinear-phi-1.5
| import gc | |
| import torch | |
| from torch import nn | |
| from bitlinear import BitLinear | |
| # Adapt from https://github.com/kyegomez/BitNet/blob/main/bitnet/replace_hf.py | |
| def replace_linear_in_hf(model, keep_param: bool): | |
| """ | |
| Replaces all instances of nn.Linear in the given model with BitLinear, except lm_head. | |
| Args: | |
| model (nn.Module): The model to modify. | |
| Returns: | |
| None | |
| :param model: The model to modify. | |
| :param keep_param: if ture, the model will keep param from the initial model. | |
| if false, the model will be using random init weight (For training) | |
| """ | |
| for name, module in model.named_children(): | |
| if isinstance(module, nn.Linear): | |
| if 'head' in name: | |
| continue | |
| # Create a new BitLinear layer with random parameters | |
| bit_linear = BitLinear( | |
| in_features=module.in_features, | |
| out_features=module.out_features, | |
| bias=module.bias is not None, | |
| ) | |
| if keep_param: | |
| # Transfer the weights and bias from the original nn.Linear to the new BitLinear | |
| bit_linear.weight.data.copy_(module.weight.data) | |
| if module.bias is not None: | |
| bit_linear.bias.data.copy_(module.bias.data) | |
| del module | |
| # Replace the nn.Linear with the new BitLinear | |
| setattr(model, name, bit_linear) | |
| else: | |
| # Recursively apply to child modules | |
| replace_linear_in_hf(module, keep_param) | |
| gc.collect() | |
| if torch.cuda.is_available(): | |
| torch.cuda.empty_cache() | |