MCPcopy Create free account
hub / github.com/FLC777/GLAT / forward

Method forward

fairseq/modules/linearized_convolution.py:44–80  ·  view source on GitHub ↗

Args: incremental_state: Used to buffer signal; if not None, then input is expected to contain a single frame. If the input order changes between time steps, call reorder_incremental_state. Input: Time x Batch x Channel during

(self, input, incremental_state: Optional[Dict[str, Dict[str, Optional[Tensor]]]] = None)

Source from the content-addressed store, hash-verified

42
43 @torch.jit.export
44 def forward(self, input, incremental_state: Optional[Dict[str, Dict[str, Optional[Tensor]]]] = None):
45 """
46 Args:
47 incremental_state: Used to buffer signal; if not None, then input is
48 expected to contain a single frame. If the input order changes
49 between time steps, call reorder_incremental_state.
50 Input:
51 Time x Batch x Channel during training
52 Batch x Time x Channel during inference
53 """
54 if incremental_state is None:
55 output = self.conv_tbc(input)
56 if self.kernel_size[0] > 1 and self.padding[0] > 0:
57 # remove future timesteps added by padding
58 output = output[: -self.padding[0], :, :]
59 return output
60
61 # reshape weight
62 weight = self._get_linearized_weight()
63 kw = self.kernel_size[0]
64
65 bsz = input.size(0) # input: bsz x len x dim
66 if kw > 1:
67 input = input.data
68 input_buffer = self._get_input_buffer(incremental_state)
69 if input_buffer is None:
70 input_buffer = input.new(bsz, kw, input.size(2)).zero_()
71 self._set_input_buffer(incremental_state, input_buffer)
72 else:
73 # shift buffer
74 input_buffer[:, :-1, :] = input_buffer[:, 1:, :].clone()
75 # append next input
76 input_buffer[:, -1, :] = input[:, -1, :]
77 input = input_buffer
78 with torch.no_grad():
79 output = F.linear(input.view(bsz, -1), weight, self.bias)
80 return output.view(bsz, 1, -1)
81
82 @torch.jit.unused
83 def reorder_incremental_state(self, incremental_state: Optional[Dict[str, Dict[str, Optional[Tensor]]]], new_order):

Callers

nothing calls this directly

Calls 5

_get_input_bufferMethod · 0.95
_set_input_bufferMethod · 0.95
conv_tbcMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected