-
Notifications
You must be signed in to change notification settings - Fork 239
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
[Good First Issue][NNCF]: Add tests for torch device utils #2579
Comments
.take |
Thank you for looking into this issue! Please let us know if you have any questions or require any help. |
Hi, @daniil-lyakhov thank you for having posted a GFI, I was looking for that :) I was wondering whether it's safe to consider only the first network layer in the function As far as I know, there are some edge cases in which torch allows you to use different Consider this example: import torch
import torch.nn as nn
class MixedTypeNet(nn.Module):
def __init__(self):
super(MixedTypeNet, self).__init__()
self.fc_f16 = nn.Linear(10, 1).to(torch.float16)
self.fc_f32 = nn.Linear(10, 1).to(torch.float32)
def forward(self, f16, f32):
x_f16 = torch.relu(self.fc_f16(f16))
x_f32 = torch.relu(self.fc_f32(f32))
return x_f16, x_f32
device = torch.device("cuda")
net = MixedTypeNet().to(device)
input_data_f16 = torch.randn(1, 10, dtype=torch.float16).to(device)
input_data_f32 = torch.randn(1, 10, dtype=torch.float32).to(device)
x_f16, x_f32 = net(input_data_f16, input_data_f32)
print("Output (f16):", x_f16)
print("Output (f32):", x_f32)
print(next(net.parameters()).dtype) In this case, the network contains 2 different types but |
Hi @DaniAffCH, thank you for the collaboration! This is a nice catch! As function CC: @alexsu52 |
### Changes This PR addresses #2579. - Add tests for torch device utils. The tests consider the case in which the model has no parameters, has all parameters on CPU, has all parameters on CUDA, and has parameters placed on different devices. In the latter, the parameters are moved on different devices randomly. - Add tests for torch `dtype` utils. The case in which the model has no parameters is also considered. - Created a test torch helper class `EmptyModel` to take into account the case in which the model has no parameters at all. - Add docstrings in utils. ### Tests I compared all the results manually checking for their correctness. The code is also compliant with the coding style having been verified with `pre-commit run` --------- Co-authored-by: Daniil Lyakhov <[email protected]>
@DaniAffCH, thank you for the contribution! |
Dear good first issue solvers, greetings!🐱
Don't miss the opportunity to contribute to our beloved project!
Context
Functions
get_model_device
,is_multidevice
andget_model_dtype
from the file https://github.com/openvinotoolkit/nncf/blob/develop/nncf/torch/utils.py are not covered by tests and don't have proper docstrings.What needs to be done?
The tasks are
*) To extend file https://github.com/openvinotoolkit/nncf/blob/develop/tests/torch/test_utils.py with tests for functions mentioned above. Please check all 3 possible scenarios:
*) To add proper docstrings for functions mentioned above
Example Pull Requests
#2526
Resources
Contact points
@daniil-lyakhov
Ticket
No response
The text was updated successfully, but these errors were encountered: