Editing Models with Task Arithmetic
Paper • 2212.04089 • Published • 8
How to use aqweteddy/ministral-tmp with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="aqweteddy/ministral-tmp")
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 AutoProcessor, AutoModelForImageTextToText
processor = AutoProcessor.from_pretrained("aqweteddy/ministral-tmp")
model = AutoModelForImageTextToText.from_pretrained("aqweteddy/ministral-tmp")
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?"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use aqweteddy/ministral-tmp with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "aqweteddy/ministral-tmp"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "aqweteddy/ministral-tmp",
"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 run hf.co/aqweteddy/ministral-tmp
How to use aqweteddy/ministral-tmp with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "aqweteddy/ministral-tmp" \
--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": "aqweteddy/ministral-tmp",
"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 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 "aqweteddy/ministral-tmp" \
--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": "aqweteddy/ministral-tmp",
"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"
}
}
]
}
]
}'How to use aqweteddy/ministral-tmp with Docker Model Runner:
docker model run hf.co/aqweteddy/ministral-tmp
This is a merge of pre-trained language models created using mergekit.
This model was merged using the Task Arithmetic merge method using /home/pinzuli/models/ministral/Ministral-3-3B-Base-2512/ as a base.
The following models were included in the merge:
The following YAML configuration was used to produce this model:
# Chat Vector Merge using Task Arithmetic
#
# This config applies the "chat vector" from an instruct model to a target model.
# The chat vector is computed as: chat_model - base_model
# Then applied as: target_model + weight * (chat_model - base_model)
#
# Since we want to apply the chat vector to our target model (checkpoint),
# we set the checkpoint as the base_model and only include the chat_model.
# The task vector (chat_model - base_model) will be computed and added back.
models:
# The instruct/chat model that provides the "chat capabilities"
- model: /home/pinzuli/models/ministral/Ministral-3-3B-Reasoning-2512
parameters:
weight:
# 1.0
- filter: embed_tokens
value: 0
- filter: lm_head
value: 0
- value: 1.0
# The target model (your fine-tuned checkpoint)
- model: /home/pinzuli/swift_trainer/output/ministral-3-3b-base_cp-v2.0.0
parameters:
weight: 1.0
merge_method: task_arithmetic
base_model: /home/pinzuli/models/ministral/Ministral-3-3B-Base-2512/
tokenizer_source: /home/pinzuli/models/ministral/Ministral-3-3B-Reasoning-2512
dtype: bfloat16