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

implement an argument to directly set ff_inner_dim #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions palm_rlhf_pytorch/palm.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(
qk_rmsnorm = False,
qk_scale = 8,
ff_mult = 4,
ff_inner_dim = None,
attn_dropout = 0.,
ff_dropout = 0.,
use_xpos = True,
Expand All @@ -134,7 +135,8 @@ def __init__(
self.norm = LayerNorm(dim)

attn_inner_dim = dim_head * heads
ff_inner_dim = dim * ff_mult
# silently ignores ff_mult if ff_inner_dim is provided in the arguments
ff_inner_dim = dim * ff_mult if not ff_inner_dim else self.ff_inner_dim

Choose a reason for hiding this comment

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

Consider adding a check to ensure that ff_inner_dim is a positive integer if it is not None. This will prevent potential errors or unexpected behavior. [important]

self.fused_dims = (attn_inner_dim, dim_head, dim_head, (ff_inner_dim * 2))

Choose a reason for hiding this comment

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

It would be beneficial to add a comment explaining why ff_inner_dim is multiplied by 2 in self.fused_dims. This would improve code readability and maintainability. [medium]


self.qk_rmsnorm = qk_rmsnorm
Expand Down Expand Up @@ -270,6 +272,7 @@ def __init__(
dim_head = 64,
heads = 8,
ff_mult = 4,
ff_inner_dim = None,
attn_dropout = 0.,
ff_dropout = 0.,
qk_rmsnorm = False,
Expand Down Expand Up @@ -297,6 +300,7 @@ def __init__(
heads = heads,
qk_rmsnorm = qk_rmsnorm,
ff_mult = ff_mult,
ff_inner_dim = ff_inner_dim,
attn_dropout = attn_dropout,
ff_dropout = ff_dropout,
xpos_scale_base = rotary_xpos_scale_base,
Expand Down Expand Up @@ -511,4 +515,4 @@ def forward(
return ret

logits = rearrange(logits, 'b n c -> b c n')
return F.cross_entropy(logits, labels, ignore_index = self.cross_entropy_ignore_index)

Choose a reason for hiding this comment

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

Consider adding a newline at the end of the file. This is a common convention that helps with file processing in various systems. [medium]

return F.cross_entropy(logits, labels, ignore_index = self.cross_entropy_ignore_index)