Skip to content

Conversation

@Isotr0py
Copy link
Member

@Isotr0py Isotr0py commented Feb 10, 2024

Related issue:

TODO:

  • Add model config OLMoConfig
  • Test on OLMo-1B
  • Test on OLMo-7B/7B-Twin-2T
  • Format code

This is still in progress before all developments and tests finish.
Done.

Comment on lines +69 to +77
class SwiGLU(nn.Module):

def forward(self, x: torch.Tensor) -> torch.Tensor:
x, gate = x.chunk(2, dim=-1)
return F.silu(gate) * x

@property
def output_multiplier(self) -> float:
return 0.5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that SwiGLU activation used in olmo is different from the SiluAndMul in vllm:

class SiluAndMul(nn.Module):
    """An activation function for SwiGLU.

    The function computes x -> silu(x[:d]) * x[d:] where d = x.shape[-1] // 2.

    Shapes:
        x: (batch_size, seq_len, 2 * d) or (num_tokens, 2 * d)
        return: (batch_size, seq_len, d) or (num_tokens, d)
    """

    def _forward(self, x: torch.Tensor) -> torch.Tensor:
        """PyTorch-native implementation equivalent to forward()."""
        d = x.shape[-1] // 2
        return F.silu(x[..., :d]) * x[..., d:]

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        d = x.shape[-1] // 2
        output_shape = (x.shape[:-1] + (d, ))
        out = torch.empty(output_shape, dtype=x.dtype, device=x.device)
        ops.silu_and_mul(out, x)
        return out

@Isotr0py Isotr0py marked this pull request as ready for review February 15, 2024 12:50
Copy link
Member

@zhuohan123 zhuohan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for your contribution!

@zhuohan123 zhuohan123 merged commit ab3a5a8 into vllm-project:main Feb 19, 2024
@Isotr0py Isotr0py deleted the olmo branch February 19, 2024 09:08
zhuohan123 added a commit that referenced this pull request Feb 21, 2024
This version is for more model support. Add support for Gemma models (#2964) and OLMo models (#2832).
simon-mo pushed a commit that referenced this pull request Feb 21, 2024
This version is for more model support. Add support for Gemma models (#2964) and OLMo models (#2832).
xjpang pushed a commit to xjpang/vllm that referenced this pull request Feb 22, 2024
xjpang pushed a commit to xjpang/vllm that referenced this pull request Feb 22, 2024
This version is for more model support. Add support for Gemma models (vllm-project#2964) and OLMo models (vllm-project#2832).
xjpang pushed a commit to xjpang/vllm that referenced this pull request Mar 4, 2024
xjpang pushed a commit to xjpang/vllm that referenced this pull request Mar 4, 2024
This version is for more model support. Add support for Gemma models (vllm-project#2964) and OLMo models (vllm-project#2832).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants