[Model] Initial support for BLIP-2 (#5920)

Co-authored-by: ywang96 <ywang@roblox.com>
This commit is contained in:
Cyrus Leung
2024-07-27 11:53:07 +00:00
committed by GitHub
co-authored by ywang96
parent ecb33a28cb
commit 1ad86acf17
12 changed files with 1107 additions and 21 deletions
+6 -5
View File
@@ -1,8 +1,9 @@
import sys
from abc import ABC, abstractmethod
from collections import UserDict, defaultdict
from typing import (Any, Callable, Dict, List, Optional, Type, TypedDict,
TypeVar, Union, cast)
from typing import Any, Callable, Dict, List, Optional
from typing import Sequence as GenericSequence
from typing import Type, TypedDict, TypeVar, Union, cast
import torch
import torch.types
@@ -15,13 +16,13 @@ from vllm.logger import init_logger
logger = init_logger(__name__)
NestedTensors = Union[List[torch.Tensor], torch.Tensor]
NestedTensors = Union[GenericSequence[torch.Tensor], torch.Tensor]
"""
Use a list instead of a tensor if the dimensions of each element do not match.
Currently only supports up to singly nested list of tensors.
"""
BatchedTensors = Union[List[NestedTensors], NestedTensors]
BatchedTensors = Union[GenericSequence[NestedTensors], NestedTensors]
"""
If each input tensor in the batch has the same size, this is a single batched
tensor; otherwise, this is a list of :class:`NestedTensors` with one element
@@ -53,7 +54,7 @@ class MultiModalInputs(_MultiModalInputsBase):
# may be list rather than tensors
if isinstance(tensors[0], list):
return [[t.to(device=device) for t in tensor[0]]
for tensor in tensors]
for tensor in cast(List[List[torch.Tensor]], tensors)]
tensors_ = cast(List[torch.Tensor], tensors)