Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MinGPT fork cse447
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ryan Bai
MinGPT fork cse447
Commits
f2764877
Commit
f2764877
authored
3 months ago
by
RyanBHC
Browse files
Options
Downloads
Patches
Plain Diff
Adding nonlinear projection in self attention
parent
82633454
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mingpt/model.py
+8
-3
8 additions, 3 deletions
mingpt/model.py
with
8 additions
and
3 deletions
mingpt/model.py
+
8
−
3
View file @
f2764877
...
@@ -83,7 +83,12 @@ class CausalSelfAttention(nn.Module):
...
@@ -83,7 +83,12 @@ class CausalSelfAttention(nn.Module):
# key, query, value projections for all heads, but in a batch
# key, query, value projections for all heads, but in a batch
# self.c_attn = nn.Linear(config.n_embd, 3 * config.n_embd)
# self.c_attn = nn.Linear(config.n_embd, 3 * config.n_embd)
# output projection
# output projection
self
.
c_proj
=
nn
.
Linear
(
config
.
n_embd
,
config
.
n_embd
)
#self.c_proj = nn.Linear(config.n_embd, config.n_embd)
self
.
c_proj
=
nn
.
Sequential
(
nn
.
Linear
(
config
.
n_embd
,
config
.
n_embd
),
nn
.
ReLU
(),
nn
.
Linear
(
config
.
n_embd
,
config
.
n_embd
)
)
# regularization
# regularization
self
.
attn_dropout
=
nn
.
Dropout
(
config
.
attn_pdrop
)
self
.
attn_dropout
=
nn
.
Dropout
(
config
.
attn_pdrop
)
self
.
resid_dropout
=
nn
.
Dropout
(
config
.
resid_pdrop
)
self
.
resid_dropout
=
nn
.
Dropout
(
config
.
resid_pdrop
)
...
@@ -102,8 +107,8 @@ class CausalSelfAttention(nn.Module):
...
@@ -102,8 +107,8 @@ class CausalSelfAttention(nn.Module):
y
[
mask_tokens
]
=
0
y
[
mask_tokens
]
=
0
# output projection
# output projection
#
y = self.resid_dropout(self.c_proj(y))
y
=
self
.
resid_dropout
(
self
.
c_proj
(
y
))
y
=
self
.
resid_dropout
(
y
)
#
y = self.resid_dropout(y)
return
y
return
y
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment