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

Add fp16 PyTorch models #152

Open
kkontny opened this issue Oct 10, 2022 · 3 comments
Open

Add fp16 PyTorch models #152

kkontny opened this issue Oct 10, 2022 · 3 comments
Assignees

Comments

@kkontny
Copy link
Contributor

kkontny commented Oct 10, 2022

In Pytorch you can convert model to fp16 with module.half() call. I think it should be called before converting to TorchScript. See docs https://pytorch.org/docs/stable/generated/torch.nn.Module.html. I think it should be quite simple implementation.

@jan-grzybek-ampere
Copy link
Member

@dkupnicki please take a look

@dkupnicki
Copy link
Collaborator

I added self.__model.half() before

self.__frozen_script = torch.jit.freeze(torch.jit.script(self.__model))

and tested a few models. All of them stopped working, but they threw slightly different errors:

  • resnet_50_v1 and a few others threw RuntimeError: "rsqrt_cpu" not implemented for 'Half'
  • alexnet and ssd_vgg_16 threw RuntimeError: expected scalar type Float but found Half
  • roberta_base_squad threw RuntimeError: "LayerNormKernelImpl" not implemented for 'Half'

Looks like half() only works on GPUs.

@kkontny
Copy link
Contributor Author

kkontny commented Oct 12, 2022

Yes, it is expected. Since x86 doesn't support fp16 natively, nobody cared about this on CPU. However Altra supports it natively, so when eager mode will be implemented I expect it to work.

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

3 participants