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

KAN takes significant time to infer by CUDA? #185

Open
hoangthangta opened this issue May 14, 2024 · 1 comment
Open

KAN takes significant time to infer by CUDA? #185

hoangthangta opened this issue May 14, 2024 · 1 comment

Comments

@hoangthangta
Copy link

hoangthangta commented May 14, 2024

I tried to set up a KAN model and found that KAN takes a lot of time to infer the output with CUDA. Here is my test code:

from kan import KAN
import torch
import time

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# without cuda
start = time.time()
model = KAN(width=[768,64,2], grid=5, k=3)
x = torch.normal(0,0.5,size=(4,768))
y = model(x)
end = time.time()
print(end - start) # 3.04 s

# with cuda
start = time.time()
model = KAN(width=[768,64,2], grid=5, k=3, device = device)
x = torch.normal(0,0.5,size=(4,768)).to(device)
y = model(x)
end = time.time()
print(end - start) # 10.9s

What happens? Do you know if I miss something here?

@AlessandroFlati
Copy link
Contributor

Simply enough, imho, the model isn't large enough and the x passed to the model isn't large enough to appreciate the parallelism as opposed to the overhead of passing that data to CUDA.

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