mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-31 19:01:28 +00:00
* feat(policies): add Nvidia Gr00t N1.5 model Co-authored-by: lbenhorin <lbenhorin@nvidia.com> Co-authored-by: Aravindh <aravindhs@nvidia.com> Co-authored-by: nv-sachdevkartik <ksachdev@nvidia.com> Co-authored-by: youliangt <youliangt@nvidia.com> Co-authored-by: Michel Aractingi <michel.aractingi@huggingface.co> Co-authored-by: Pepijn <138571049+pkooij@users.noreply.github.com> Co-authored-by: Jade Choghari <chogharijade@gmail.com> * fix(docs): add groot to index Co-authored-by: sachdevkartik <sachdev.kartik25@gmail.com> --------- Co-authored-by: lbenhorin <lbenhorin@nvidia.com> Co-authored-by: Aravindh <aravindhs@nvidia.com> Co-authored-by: nv-sachdevkartik <ksachdev@nvidia.com> Co-authored-by: youliangt <youliangt@nvidia.com> Co-authored-by: Michel Aractingi <michel.aractingi@huggingface.co> Co-authored-by: Pepijn <138571049+pkooij@users.noreply.github.com> Co-authored-by: Jade Choghari <chogharijade@gmail.com> Co-authored-by: sachdevkartik <sachdev.kartik25@gmail.com>
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import torch
|
|
import torch.nn as nn
|
|
|
|
|
|
def swish(x):
|
|
return x * torch.sigmoid(x)
|
|
|
|
|
|
class SinusoidalPositionalEncoding(nn.Module):
|
|
"""
|
|
Produces a sinusoidal encoding of shape (B, T, w)
|
|
given timesteps of shape (B, T).
|
|
"""
|
|
|
|
def __init__(self, embedding_dim):
|
|
super().__init__()
|
|
self.embedding_dim = embedding_dim
|
|
|
|
def forward(self, timesteps):
|
|
# timesteps: shape (B, T)
|
|
# We'll compute sin/cos frequencies across dim T
|
|
timesteps = timesteps.float() # ensure float
|
|
|
|
b, t = timesteps.shape
|
|
device = timesteps.device
|
|
|
|
half_dim = self.embedding_dim // 2
|
|
# typical log space frequencies for sinusoidal encoding
|
|
exponent = -torch.arange(half_dim, dtype=torch.float, device=device) * (
|
|
torch.log(torch.tensor(10000.0)) / half_dim
|
|
)
|
|
# Expand timesteps to (B, T, 1) then multiply
|
|
freqs = timesteps.unsqueeze(-1) * exponent.exp() # (B, T, half_dim)
|
|
|
|
sin = torch.sin(freqs)
|
|
cos = torch.cos(freqs)
|
|
enc = torch.cat([sin, cos], dim=-1) # (B, T, w)
|
|
|
|
return enc
|