Add Tensor Input Support: Enable .pt file processing with <tensor> tags for latent representations #6451
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR type
PR information
Add Tensor Input Support for Latent Representations
Motivation
This PR adds support for loading and processing PyTorch tensor files (
.ptformat) using<tensor>tags, similar to how<image>and<video>tags work in MS-Swift. This enables training VLMs with pre-computed embeddings and latent representations from encoder models.Key Use Case: Latent-VLM Architecture
This feature was developed for my latent-vlm project, which uses pre-encoded latent representations instead of raw images/videos. Benefits include:
Instead of storing and processing raw images/videos repeatedly during training, you can:
.pttensor files<tensor>tagsCore Idea
Extend MS-Swift's multimodal support to handle tensor files the same way it handles images and videos:
Before (Images/Videos only):
{"messages": [...], "images": ["image.jpg"], "videos": ["video.mp4"]}