[GH-ISSUE #292] Question: Is it possible to use the image tensor as float32 without converting it to float16? #252

Closed
opened 2026-10-31 21:12:57 +00:00 by bsakaguchi · 2 comments
Owner

Originally created by @blackbeandu on GitHub (Sep 28, 2022).
Original GitHub issue: https://github.com/openai/CLIP/issues/292

The title is the content.

Thank you.

Originally created by @blackbeandu on GitHub (Sep 28, 2022). Original GitHub issue: https://github.com/openai/CLIP/issues/292 The title is the content. Thank you.
Author
Owner

@Asthestarsfalll commented on GitHub (Sep 28, 2022):

There you may find the way of converting weights dtype to float32.
Just modify like this:

    if not jit:
        model = build_model(state_dict or model.state_dict()).to(device)
        model.float()
        return model, _transform(model.visual.input_resolution)

or you can convert it after load model:

clip = load('RN50')
clip.float()

Btw, I test the clip with dtype float32, but the acc on ImageNet has a litlle decrease.

<!-- gh-comment-id:1260250491 --> @Asthestarsfalll commented on GitHub (Sep 28, 2022): [There](https://github.com/openai/CLIP/blob/main/clip/clip.py#L138) you may find the way of converting weights dtype to float32. Just modify like this: ```python if not jit: model = build_model(state_dict or model.state_dict()).to(device) model.float() return model, _transform(model.visual.input_resolution) ``` or you can convert it after load model: ```python clip = load('RN50') clip.float() ``` Btw, I test the clip with dtype float32, but the acc on ImageNet has a litlle decrease.
Author
Owner

@blackbeandu commented on GitHub (Sep 28, 2022):

There you may find the way of converting weights dtype to float32. Just modify like this:

    if not jit:
        model = build_model(state_dict or model.state_dict()).to(device)
        model.float()
        return model, _transform(model.visual.input_resolution)

or you can convert it after load model:

clip = load('RN50')
clip.float()

Btw, I test the clip with dtype float32, but the acc on ImageNet has a litlle decrease.

Thanks for the answers @Asthestarsfalll
I solved it.

<!-- gh-comment-id:1260268957 --> @blackbeandu commented on GitHub (Sep 28, 2022): > [There](https://github.com/openai/CLIP/blob/main/clip/clip.py#L138) you may find the way of converting weights dtype to float32. Just modify like this: > > ```python > if not jit: > model = build_model(state_dict or model.state_dict()).to(device) > model.float() > return model, _transform(model.visual.input_resolution) > ``` > > or you can convert it after load model: > > ```python > clip = load('RN50') > clip.float() > ``` > > Btw, I test the clip with dtype float32, but the acc on ImageNet has a litlle decrease. Thanks for the answers @Asthestarsfalll I solved it.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#252
No description provided.