Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
d5b82bb7
Unverified
Commit
d5b82bb7
authored
Oct 15, 2021
by
jacksukk
Committed by
GitHub
Oct 14, 2021
Browse files
Fixed horizon_length for PPLM (#13886)
* fixed horizon_length * fixed horizon_length * fix style
parent
5b317f7e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletion
+8
-1
examples/research_projects/pplm/run_pplm.py
examples/research_projects/pplm/run_pplm.py
+8
-1
No files found.
examples/research_projects/pplm/run_pplm.py
View file @
d5b82bb7
...
@@ -181,7 +181,14 @@ def perturb_past(
...
@@ -181,7 +181,14 @@ def perturb_past(
for
_
in
range
(
horizon_length
):
for
_
in
range
(
horizon_length
):
inputs_embeds
=
torch
.
matmul
(
curr_probs
,
wte
.
weight
.
data
)
inputs_embeds
=
torch
.
matmul
(
curr_probs
,
wte
.
weight
.
data
)
lm_output
=
model
(
past_key_values
=
curr_unpert_past
,
inputs_embeds
=
inputs_embeds
)
lm_output
=
model
(
past_key_values
=
curr_unpert_past
,
inputs_embeds
=
inputs_embeds
)
curr_unpert_past
,
curr_all_hidden
=
lm_output
[
"past_key_values"
],
lm_output
[
"hidden_states"
]
curr_all_logits
,
curr_unpert_past
,
curr_all_hidden
=
(
lm_output
[
"logits"
],
lm_output
[
"past_key_values"
],
lm_output
[
"hidden_states"
],
)
curr_logits
=
curr_all_logits
[:,
-
1
,
:]
curr_probs
=
nn
.
functional
.
softmax
(
curr_logits
,
dim
=-
1
)
curr_probs
=
torch
.
unsqueeze
(
curr_probs
,
dim
=
1
)
curr_hidden
=
curr_all_hidden
[
-
1
]
curr_hidden
=
curr_all_hidden
[
-
1
]
new_accumulated_hidden
=
new_accumulated_hidden
+
torch
.
sum
(
curr_hidden
,
dim
=
1
)
new_accumulated_hidden
=
new_accumulated_hidden
+
torch
.
sum
(
curr_hidden
,
dim
=
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment