-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Support more model outputs for BERT/ERNIE/RoBERTa #2583
Conversation
|
||
import inspect | ||
import dataclasses | ||
from collections import OrderedDict, UserDict | ||
from collections.abc import MutableMapping | ||
from contextlib import ExitStack | ||
from dataclasses import fields, dataclass | ||
from enum import Enum | ||
from typing import Any, ContextManager, List, Tuple, Optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的 import 是否应该挪到文件开头位置
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
all_hidden_states = [] if output_hidden_states else None | ||
for i, mod in enumerate(self.layers): | ||
layer_outputs = mod(output, | ||
src_mask=src_mask, | ||
cache=None if cache is None else cache[i], | ||
output_attentions=output_attentions) | ||
if isinstance(layer_outputs, tuple): | ||
output = layer_outputs[0] | ||
outputs = layer_outputs[1:] | ||
else: | ||
output = layer_outputs | ||
outputs = None | ||
|
||
if output_hidden_states: | ||
all_hidden_states.append(output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HF 中的 all_hidden_states 包含了 embedding_output,这里的实现相比会少这个 Tensor。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This reverts commit dab5e26.
PR types
New features
PR changes
APIs
Description
Support more model outputs for BERT. The default behavior is the same as before for compatibility.
Import more output structures refer to HF.
Usage: