Ultralytics YOLO27:
License YOLO
Back to Ultralytics Glossary

Task Vectors

A task vector is the difference between fine-tuned and base model weights, capturing one skill so it can be added, removed or merged. Covers uses.

Task vectors represent the specific changes made to a neural network's weights during fine-tuning to achieve a new capability. By subtracting the parameters of a foundational base model from those of a fine-tuned model, researchers can isolate a directional vector in the weight space that encapsulates the learned behavior for that specific task. This approach allows developers to apply simple arithmetic operations on model parameters to steer, modify, or merge model behaviors without requiring additional training compute.

How Task Vectors Differentiate From Transfer Learning#

While the concept of transfer learning involves sequentially training a model on a new dataset to adapt its existing knowledge, task vectors operate directly on the model's structural weights post-training. Instead of retraining gradients to learn a new domain, weight space interpolation using task vectors allows practitioners to linearly combine the weight differences from multiple independently trained models. This enables zero-shot model merging, allowing a single model to inherit multiple capabilities simultaneously without the typical computational overhead during training.

Real-World Applications#

The ability to manipulate deep learning models algebraically has led to several impactful applications across modern AI pipelines:

  • Multi-Task Model Merging: Engineers can combine task vectors from fine-tunes of the same base model, such as two object detection models trained on different datasets; task vectors only combine across identical architectures, so a detection fine-tune cannot be merged with an image segmentation one. When applied to an Ultralytics YOLO26 base model, this creates a single model that inherits the strengths of each original fine-tune.
  • Machine Unlearning and AI Safety: If a model exhibits biased or dangerous outputs, researchers can calculate a task vector representing that specific unwanted behavior. By subtracting this vector from the model's weights, they can effectively "erase" the behavior, contributing heavily to improved AI safety and robust AI ethics standards.
  • Domain Adaptation in Computer Vision: When adapting models for specific environments—such as shifting from daytime to nighttime real-time inference—task vectors allow users to scale the magnitude of the adaptation. Applying a fraction of the vector (e.g., a scaling factor of 0.5) can yield a balanced model that performs well in both domains.

Working with Task Vectors in PyTorch#

Creating and applying a task vector requires accessing and manipulating the PyTorch state dictionary. The following example demonstrates how to extract a task vector from a fine-tuned Ultralytics YOLO26 model and apply it back to the base model with a specific scaling factor.

from ultralytics import YOLO

# Load the state dictionaries for the base and fine-tuned models
base_weights = YOLO("yolo26n.pt").model.state_dict()
tuned_weights = YOLO("yolo26n-custom.pt").model.state_dict()

# Calculate the task vector (tuned weights minus base weights), skipping integer buffers
task_vector = {k: tuned_weights[k] - base_weights[k] for k in base_weights if base_weights[k].is_floating_point()}

# Apply the task vector to the base model using a 0.5 scaling factor
for k, delta in task_vector.items():
    base_weights[k] += 0.5 * delta

The Future of Weight Manipulation#

As architectures like large language models and massive vision transformers grow in parameter count, retraining them for every minor adjustment becomes economically unfeasible. Task vectors provide a mathematically elegant alternative for post-training model optimization. By sharing lightweight task vectors instead of entire multi-gigabyte models, the AI community can accelerate open-source collaboration in AI. Once your custom task vectors are refined, utilizing the Ultralytics Platform simplifies the subsequent model deployment and monitoring processes, ensuring your optimized weights translate directly into production-ready endpoints.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning