Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I define a cell rather than a layer? #11

Open
GELIELEO opened this issue Jul 5, 2024 · 2 comments
Open

How can I define a cell rather than a layer? #11

GELIELEO opened this issue Jul 5, 2024 · 2 comments

Comments

@GELIELEO
Copy link

GELIELEO commented Jul 5, 2024

No description provided.

@KhaleelKhan
Copy link
Member

Hello @GELIELEO ,

Defining a Cell instead of a Layer is not possible with the interface we currently provide since this is a optimized implementation. Cell interface is currently under development.

@KhaleelKhan
Copy link
Member

update: please check branch feature/egru_cell. Example usage is given below.

import torch
import evnn_pytorch as evnn

input_size = 128
hidden_size = 16
batch_size = 5

# setting use_custom_cuda=False makes the model use pytorch code instead of EvNN extension, 
# has no effect on the step function which is only implemented in pytorch
egru_cell =  evnn.EGRU(input_size, hidden_size, batch_first=False, use_custom_cuda=True)

egru_cell.cuda()

timesteps=25
# `x` is a CUDA tensor with shape [N,T,C]
x = torch.rand([timesteps, batch_size, input_size]).cuda()
y = []
y_t = None
h_t = None

for t in range(timesteps):
    x_t = x[t]
    y_t, h_t, _ = egru_cell.step(x_t, y_t, h_t)
    y.append(y_t)

y = torch.stack(y, dim=0)

# Sanity check, some numerical error from float conversion is expected 
assert torch.allclose(y, egru_cell(x)[0], atol=5e-4)

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

No branches or pull requests

2 participants