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

fix AttributeError caused by last_hidden_state #107

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
7 changes: 4 additions & 3 deletions angle_emb/angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,12 +712,13 @@ def __call__(self,
:param return_mlm_logits: bool. Return logits or not. Default False.
"""
if layer_index == -1 and not return_all_layer_outputs:
ret = self.model(**inputs)
outputs = ret.last_hidden_state
ret = self.model(output_hidden_states=True, **inputs)
outputs = ret.last_hidden_state if hasattr(ret, 'last_hidden_state') else ret.hidden_states[-1]
else:
ret = self.model(output_hidden_states=True, return_dict=True, **inputs)
all_layer_outputs = list(ret.hidden_states)
all_layer_outputs[-1] = ret.last_hidden_state
if hasattr(ret, 'last_hidden_state'):
all_layer_outputs[-1] = ret.last_hidden_state
if return_all_layer_outputs:
return (all_layer_outputs, ret.logits) if return_mlm_logits else all_layer_outputs
outputs = all_layer_outputs[layer_index]
Expand Down
Loading