[GH-ISSUE #171] Change dtype on inference #149

Closed
opened 2026-10-31 21:11:43 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @MaxKochanov on GitHub (Nov 2, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/171

Hello!

In the issue #30 you answered: "Empirically, we have been doing CLIP inference in fp16 without much problem, and that's how the model was trained for anyway".

In this case I have two questions:

  1. Is there any chance to change dtype of CLIP weights from float32 to float16 and use it on GPU? You said "without much problem", and I`ve already dived into the code, but I have not succeed to change the dtype correctly.

  2. Do I understand right that you trained CLIP on float32?

Originally created by @MaxKochanov on GitHub (Nov 2, 2021). Original GitHub issue: https://github.com/openai/CLIP/issues/171 Hello! In the issue #30 you answered: "Empirically, we have been doing CLIP inference in fp16 without much problem, and that's how the model was trained for anyway". In this case I have two questions: 1) Is there any chance to change dtype of CLIP weights from float32 to float16 and use it on GPU? You said "without much problem", and I`ve already dived into the code, but I have not succeed to change the dtype correctly. 2) Do I understand right that you trained CLIP on float32?
Author
Owner

@jongwook commented on GitHub (Nov 16, 2021):

  1. For most of weights it's safe to convert the parameter dtypes to float16, but some operations like LayerNorm needs to be done in fp32 for stable training. We convert some of the weights depending on the layer's type; see convert_weights().

  2. We used mixed precision training for training CLIP, as mentioned in Section 2.5 of the paper.

<!-- gh-comment-id:969679493 --> @jongwook commented on GitHub (Nov 16, 2021): 1. For most of weights it's safe to convert the parameter dtypes to float16, but some operations like [LayerNorm](https://github.com/openai/CLIP/blob/3b473b0e682c091a9e53623eebc1ca1657385717/clip/model.py#L153-L159) needs to be done in fp32 for stable training. We convert some of the weights depending on the layer's type; see [convert_weights()](https://github.com/openai/CLIP/blob/3b473b0e682c091a9e53623eebc1ca1657385717/clip/model.py#L371-L392). 2. We used mixed precision training for training CLIP, as mentioned in Section 2.5 of the paper.
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#149
No description provided.