Skip to content

Question about calculating gradients #27

@OLibykov

Description

@OLibykov

Hi, thanks for your work. I'm looking at your implementation,

one_hot.scatter_(

and maybe I'm missing something, but when you do

one_hot.scatter_(
1,
input_ids[0][:control_length].unsqueeze(1),
torch.ones(one_hot.shape[0], 1, device=model.device, dtype=embed_weights.dtype)
)

You access the CLS (<|startoftext|>) token and then run the gradient over it.

If I understand correctly, you should do something like
one_hot.scatter_(1, input_ids[0][1:control_length+1].unsqueeze(1), ....)

and then

full_embeds = torch.cat([embeds[:, 0:1], input_embeds, embeds[:, control_length+1:]], dim=1).

What do you think about this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions