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

⚠️ [CLAP] Fix dtype of logit scales in init #25682

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/transformers/models/clap/modeling_clap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from dataclasses import dataclass
from typing import Any, List, Optional, Tuple, Union

import numpy as np
import torch
import torch.nn.functional as F
from torch import nn
Expand Down Expand Up @@ -1956,8 +1955,8 @@ def __init__(self, config: ClapConfig):
text_config = config.text_config
audio_config = config.audio_config

self.logit_scale_a = nn.Parameter(torch.tensor(np.log(config.logit_scale_init_value)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aforementioned behaviour is a result of the np.log operation defaulting to float64

Copy link
Collaborator

@ArthurZucker ArthurZucker Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the original code we might need to init in float64 then cast to float if it makes a difference. No idea if the actual value save is in float64!

Copy link
Contributor Author

@sanchit-gandhi sanchit-gandhi Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameters are initialised in float64 but are stored in float32 in the state dict

self.logit_scale_t = nn.Parameter(torch.tensor(np.log(config.logit_scale_init_value)))
self.logit_scale_a = nn.Parameter(torch.log(torch.tensor(config.logit_scale_init_value)))
self.logit_scale_t = nn.Parameter(torch.log(torch.tensor(config.logit_scale_init_value)))

self.projection_dim = config.projection_dim

Expand Down