Unverified Commit d5b82bb7 authored by jacksukk's avatar jacksukk Committed by GitHub
Browse files

Fixed horizon_length for PPLM (#13886)

* fixed horizon_length

* fixed horizon_length

* fix style
parent 5b317f7e
...@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment