[Misc] Added missing return type annotations to improve mypy and IDE tooling (#43383)
Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
This commit is contained in:
@@ -64,7 +64,7 @@ def resolve_classifier_act_fn(
|
||||
model_config: ModelConfig,
|
||||
static_num_labels: bool = True,
|
||||
act_fn: "PoolerActivation | None" = None,
|
||||
):
|
||||
) -> "PoolerActivation":
|
||||
if act_fn is None:
|
||||
return get_act_fn(model_config.hf_config, static_num_labels)
|
||||
|
||||
@@ -78,7 +78,7 @@ _T = TypeVar("_T", torch.Tensor, list[torch.Tensor])
|
||||
|
||||
class PoolerActivation(nn.Module, ABC):
|
||||
@staticmethod
|
||||
def wraps(module: nn.Module):
|
||||
def wraps(module: nn.Module) -> "PoolerActivation":
|
||||
if isinstance(module, nn.Identity):
|
||||
return PoolerIdentity()
|
||||
if isinstance(module, (nn.Sigmoid, nn.Softmax)):
|
||||
@@ -140,7 +140,7 @@ class PoolerClassify(PoolerActivation):
|
||||
|
||||
|
||||
class LambdaPoolerActivation(PoolerActivation):
|
||||
def __init__(self, fn: Callable[[torch.Tensor], torch.Tensor]):
|
||||
def __init__(self, fn: Callable[[torch.Tensor], torch.Tensor]) -> None:
|
||||
super().__init__()
|
||||
|
||||
self.fn = fn
|
||||
|
||||
@@ -108,7 +108,9 @@ class MeanPool(SequencePoolingMethod):
|
||||
return segment_sums / prompt_lens.unsqueeze(1)
|
||||
|
||||
|
||||
def get_seq_pooling_method(pooling_type: SequencePoolingType | str):
|
||||
def get_seq_pooling_method(
|
||||
pooling_type: SequencePoolingType | str,
|
||||
) -> SequencePoolingMethod:
|
||||
if pooling_type == "CLS":
|
||||
return CLSPool()
|
||||
if pooling_type == "LAST":
|
||||
|
||||
@@ -102,6 +102,7 @@ class DispatchPooler(Pooler):
|
||||
# portion of the batch. Token offset is computed from the CPU
|
||||
# `num_scheduled_tokens_cpu` to avoid a GPU->CPU sync.
|
||||
group_cursor = group_metadata.pooling_cursor
|
||||
assert group_cursor is not None
|
||||
num_group_tokens = int(group_cursor.num_scheduled_tokens_cpu.sum())
|
||||
group_hidden_states = hidden_states[
|
||||
token_offset : token_offset + num_group_tokens
|
||||
|
||||
Reference in New Issue
Block a user