(self, inference)
Dynamically grow or shrink the number of time steps to perform
        single time step fprop during inference.
Dynamically grow or shrink the number of time steps to perform
        single time step fprop during inference.
Dynamically grow or shrink the number of time steps to perform single time step fprop during inference .
def switch_mode(self, inference):
        """
        Dynamically grow or shrink the number of time steps to perform
        single time step fprop during inference.
        """
        # set up parameters
        hasLUT = isinstance(self.layers[0], LookupTable)

        # sequence length is different dimension depending on whether there is LUT
        cur_steps = self.in_shape[0] if hasLUT else self.in_shape[1]
        if not inference:
            old_size = cur_steps
            # assumes encoder and decoder have the same sequence length
            new_size = self.full_steps
        else:
            old_size = cur_steps
            new_size = 1

        # resize buffers
        if old_size != new_size:
            if hasLUT:
                in_obj = (new_size, 1)
                self.layers[0].inputs = None  # ensure "allocate" will reallocate this buffer
                self.layers[0].outputs_t = None
            else:
                in_obj = (self.out_shape[0], new_size)
            self.configure(in_obj=in_obj)
            # set layer outputs to None so they get reallocated
            for l in self.layers:
                if l.owns_output:
                    l.outputs = None
            self.allocate(shared_outputs=None)  # re-allocate deltas, but not weights
            for l in self.layers:
                l.name += "'"
def switch_mode ( self , inference ) : # set up parameters hasLUT = isinstance ( self . layers [ 0 ] , LookupTable ) # sequence length is different dimension depending on whether there is LUT cur_steps = self . in_shape [ 0 ] if hasLUT else self . in_shape [ 1 ] if not inference : old_size = cur_steps # assumes encoder and decoder have the same sequence length new_size = self . full_steps else : old_size = cur_steps new_size = 1 # resize buffers if old_size != new_size : if hasLUT : in_obj = ( new_size , 1 ) self . layers [ 0 ] . inputs = None # ensure "allocate" will reallocate this buffer self . layers [ 0 ] . outputs_t = None else : in_obj = ( self . out_shape [ 0 ] , new_size ) self . configure ( in_obj = in_obj ) # set layer outputs to None so they get reallocated for l in self . layers : if l . owns_output : l . outputs = None self . allocate ( shared_outputs = None ) # re-allocate deltas, but not weights for l in self . layers : l . name += "'"