Instructions to use internlm/internlm-xcomposer2-7b-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/internlm-xcomposer2-7b-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="internlm/internlm-xcomposer2-7b-4bit", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("internlm/internlm-xcomposer2-7b-4bit", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use internlm/internlm-xcomposer2-7b-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "internlm/internlm-xcomposer2-7b-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/internlm-xcomposer2-7b-4bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/internlm/internlm-xcomposer2-7b-4bit
- SGLang
How to use internlm/internlm-xcomposer2-7b-4bit 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 "internlm/internlm-xcomposer2-7b-4bit" \ --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": "internlm/internlm-xcomposer2-7b-4bit", "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 "internlm/internlm-xcomposer2-7b-4bit" \ --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": "internlm/internlm-xcomposer2-7b-4bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use internlm/internlm-xcomposer2-7b-4bit with Docker Model Runner:
docker model run hf.co/internlm/internlm-xcomposer2-7b-4bit
Update README.md
#2
by LinJulia - opened
README.md
CHANGED
|
@@ -31,6 +31,7 @@ This is the 4-bit version of InternLM-XComposer2, install the latest version of
|
|
| 31 |
|
| 32 |
```python
|
| 33 |
import torch, auto_gptq
|
|
|
|
| 34 |
from transformers import AutoModel, AutoTokenizer
|
| 35 |
from auto_gptq.modeling import BaseGPTQForCausalLM
|
| 36 |
|
|
@@ -62,12 +63,12 @@ img_path_list = [
|
|
| 62 |
images = []
|
| 63 |
for img_path in img_path_list:
|
| 64 |
image = Image.open(img_path).convert("RGB")
|
| 65 |
-
image =
|
| 66 |
images.append(image)
|
| 67 |
image = torch.stack(images)
|
| 68 |
query = '<ImageHere> <ImageHere>please write an article based on the images. Title: my favorite animal.'
|
| 69 |
with torch.cuda.amp.autocast():
|
| 70 |
-
response, history =
|
| 71 |
print(response)
|
| 72 |
|
| 73 |
#My Favorite Animal: The Panda
|
|
|
|
| 31 |
|
| 32 |
```python
|
| 33 |
import torch, auto_gptq
|
| 34 |
+
from PIL import Image
|
| 35 |
from transformers import AutoModel, AutoTokenizer
|
| 36 |
from auto_gptq.modeling import BaseGPTQForCausalLM
|
| 37 |
|
|
|
|
| 63 |
images = []
|
| 64 |
for img_path in img_path_list:
|
| 65 |
image = Image.open(img_path).convert("RGB")
|
| 66 |
+
image = model.vis_processor(image)
|
| 67 |
images.append(image)
|
| 68 |
image = torch.stack(images)
|
| 69 |
query = '<ImageHere> <ImageHere>please write an article based on the images. Title: my favorite animal.'
|
| 70 |
with torch.cuda.amp.autocast():
|
| 71 |
+
response, history = model.chat(tokenizer, query=query, image=image, history=[], do_sample=False)
|
| 72 |
print(response)
|
| 73 |
|
| 74 |
#My Favorite Animal: The Panda
|