[Model] Port over CLIPVisionModel for VLMs (#5591)

This commit is contained in:
Roger Wang
2024-06-20 04:52:09 -07:00
committed by GitHub
parent 111af1fa2c
commit ad137cd111
9 changed files with 269 additions and 21 deletions

View File

@@ -141,6 +141,21 @@ class FastGELU(CustomOp):
return out
class QuickGELU(CustomOp):
# https://github.com/huggingface/transformers/blob/main/src/transformers/activations.py#L90
def forward_native(self, x: torch.Tensor) -> torch.Tensor:
"""PyTorch-native implementation equivalent to forward()."""
return x * torch.sigmoid(1.702 * x)
def forward_cuda(self, x: torch.Tensor) -> torch.Tensor:
from vllm import _custom_ops as ops
out = torch.empty_like(x)
ops.gelu_quick(out, x)
return out
class ScaledActivation(nn.Module):
"""An activation function with post-scale parameters.
@@ -189,6 +204,7 @@ _ACTIVATION_REGISTRY = {
"gelu_new": NewGELU(),
"gelu_pytorch_tanh": nn.GELU(approximate="tanh"),
"relu": nn.ReLU(),
"quick_gelu": QuickGELU(),
}