本文整理汇总了Python中fairseq.models.FairseqIncrementalDecoder方法的典型用法代码示例。如果您正苦于以下问题:Python models.FairseqIncrementalDecoder方法的具体用法?Python models.FairseqIncrementalDecoder怎么用?Python models.FairseqIncrementalDecoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fairseq.models
的用法示例。
在下文中一共展示了models.FairseqIncrementalDecoder方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def __init__(self, models):
super().__init__()
self.models_size = len(models)
# method '__len__' is not supported in ModuleList for torch script
self.single_model = models[0]
self.models = nn.ModuleList(models)
self.incremental_states = torch.jit.annotate(
List[Dict[str, Dict[str, Optional[Tensor]]]],
[
torch.jit.annotate(Dict[str, Dict[str, Optional[Tensor]]], {})
for i in range(self.models_size)
],
)
self.has_incremental: bool = False
if all(
hasattr(m, "decoder") and isinstance(m.decoder, FairseqIncrementalDecoder)
for m in models
):
self.has_incremental = True
示例2: __init__
# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def __init__(self, models):
super().__init__()
self.models_size = len(models)
# method '__len__' is not supported in ModuleList for torch script
self.single_model = models[0]
self.models = nn.ModuleList(models)
self.has_incremental: bool = False
if all(
hasattr(m, "decoder") and isinstance(m.decoder, FairseqIncrementalDecoder)
for m in models
):
self.has_incremental = True
示例3: reorder_states
# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def reorder_states(self, new_order, incremental_states):
if new_order is None:
return
for model in self.models:
if isinstance(model.decoder, FairseqIncrementalDecoder):
model.decoder.reorder_incremental_state(
incremental_states[model], new_order
)
示例4: _init_incremental_states
# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def _init_incremental_states(self, n_srcs):
incremental_states = {}
for src_id in range(n_srcs):
for model_id, model in enumerate(self.models):
if isinstance(model.decoder, FairseqIncrementalDecoder):
incremental_states[(src_id, model_id)] = {}
else:
incremental_states[(src_id, model_id)] = None
return incremental_states
示例5: _encode
# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def _encode(self, encoder_input):
encoder_outs = []
incremental_states = {}
for model in self.models:
if not self.retain_dropout:
model.eval()
if isinstance(model.decoder, FairseqIncrementalDecoder):
incremental_states[model] = {}
else:
incremental_states[model] = None
encoder_out = model.encoder(*encoder_input)
encoder_outs.append(encoder_out)
return encoder_outs, incremental_states
示例6: __init__
# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def __init__(self, models):
super().__init__()
self.models = torch.nn.ModuleList(models)
self.incremental_states = None
if all(isinstance(m.decoder, FairseqIncrementalDecoder) for m in models):
self.incremental_states = {m: {} for m in models}