code
stringlengths
17
6.64M
class Partition9(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:9'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1] self.lookup = {'l_0': 'encoder.12.0.SelfAttention.dropout', 'l_1': 'encoder.12.0.SelfAttention.o', 'l_2': 'encoder.12.0.dropout', 'l_3': 'encoder.12.1.layer_norm', 'l_4': 'encoder.12.1.DenseReluDense.wi', 'l_5': 'encoder.12.1.DenseReluDense.dropout', 'l_6': 'encoder.12.1.DenseReluDense.wo', 'l_7': 'encoder.12.1.dropout', 'l_8': 'encoder.13.0.layer_norm', 'l_9': 'encoder.13.0.SelfAttention.q', 'l_10': 'encoder.13.0.SelfAttention.k'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = x1.view(x2, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = x3.float() t_1 = torch.nn.functional.softmax(t_1, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_1.type_as(x3) t_1 = self.l_0(t_1) t_0 = torch.matmul(t_1, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_0 = t_0.view(x2, (- 1), 4096) t_0 = self.l_1(t_0) t_0 = self.l_2(t_0) t_0 = (x0 + t_0) t_1 = self.l_3(t_0) t_1 = self.l_4(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_5(t_1) t_1 = self.l_6(t_1) t_1 = self.l_7(t_1) t_1 = (t_0 + t_1) t_0 = self.l_8(t_1) t_2 = t_0.size() t_3 = self.l_9(t_0) t_4 = self.l_10(t_0) t_2 = t_2[0] t_3 = t_3.view(t_2, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_2, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) return list(flatten((t_1, t_0, t_2, t_3, t_4))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition10(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:10'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'encoder.13.0.SelfAttention.v', 'l_1': 'encoder.13.0.SelfAttention.dropout', 'l_2': 'encoder.13.0.SelfAttention.o', 'l_3': 'encoder.13.0.dropout', 'l_4': 'encoder.13.1.layer_norm', 'l_5': 'encoder.13.1.DenseReluDense.wi', 'l_6': 'encoder.13.1.DenseReluDense.dropout', 'l_7': 'encoder.13.1.DenseReluDense.wo', 'l_8': 'encoder.13.1.dropout', 'l_9': 'encoder.14.0.layer_norm', 'l_10': 'encoder.14.0.SelfAttention.q', 'l_11': 'encoder.14.0.SelfAttention.k'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4, x5) = unflatten(args, self.input_structure) t_0 = self.l_0(x2) t_0 = t_0.view(x3, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = x5.transpose(3, 2) t_1 = torch.matmul(x4, t_1) t_1 += x0 t_2 = t_1.float() t_2 = torch.nn.functional.softmax(t_2, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_2.type_as(t_1) t_1 = self.l_1(t_1) t_0 = torch.matmul(t_1, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_0 = t_0.view(x3, (- 1), 4096) t_0 = self.l_2(t_0) t_0 = self.l_3(t_0) t_0 = (x1 + t_0) t_1 = self.l_4(t_0) t_1 = self.l_5(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_6(t_1) t_1 = self.l_7(t_1) t_1 = self.l_8(t_1) t_1 = (t_0 + t_1) t_0 = self.l_9(t_1) t_2 = t_0.size() t_3 = self.l_10(t_0) t_4 = self.l_11(t_0) t_2 = t_2[0] t_3 = t_3.view(t_2, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_2, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_3, t_4) t_4 += x0 return list(flatten((x0, t_1, t_0, t_2, t_4))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition11(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:11'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1] self.lookup = {'l_0': 'encoder.14.0.SelfAttention.v', 'l_1': 'encoder.14.0.SelfAttention.dropout', 'l_2': 'encoder.14.0.SelfAttention.o', 'l_3': 'encoder.14.0.dropout', 'l_4': 'encoder.14.1.layer_norm', 'l_5': 'encoder.14.1.DenseReluDense.wi', 'l_6': 'encoder.14.1.DenseReluDense.dropout', 'l_7': 'encoder.14.1.DenseReluDense.wo', 'l_8': 'encoder.14.1.dropout', 'l_9': 'encoder.15.0.layer_norm', 'l_10': 'encoder.15.0.SelfAttention.q', 'l_11': 'encoder.15.0.SelfAttention.k', 'l_12': 'encoder.15.0.SelfAttention.v', 'l_13': 'encoder.15.0.SelfAttention.dropout', 'l_14': 'encoder.15.0.SelfAttention.o', 'l_15': 'encoder.15.0.dropout', 'l_16': 'encoder.15.1.layer_norm', 'l_17': 'encoder.15.1.DenseReluDense.wi', 'l_18': 'encoder.15.1.DenseReluDense.dropout'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4) = unflatten(args, self.input_structure) t_0 = self.l_0(x2) t_0 = t_0.view(x3, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = x4.float() t_1 = torch.nn.functional.softmax(t_1, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_1.type_as(x4) t_1 = self.l_1(t_1) t_0 = torch.matmul(t_1, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_0 = t_0.view(x3, (- 1), 4096) t_0 = self.l_2(t_0) t_0 = self.l_3(t_0) t_0 = (x1 + t_0) t_1 = self.l_4(t_0) t_1 = self.l_5(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_6(t_1) t_1 = self.l_7(t_1) t_1 = self.l_8(t_1) t_1 = (t_0 + t_1) t_0 = self.l_9(t_1) t_2 = t_0.size() t_3 = self.l_10(t_0) t_4 = self.l_11(t_0) t_0 = self.l_12(t_0) t_2 = t_2[0] t_3 = t_3.view(t_2, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_2, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_0 = t_0.view(t_2, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_3, t_4) t_4 += x0 t_3 = t_4.float() t_3 = torch.nn.functional.softmax(t_3, dim=(- 1), _stacklevel=3, dtype=None) t_4 = t_3.type_as(t_4) t_4 = self.l_13(t_4) t_0 = torch.matmul(t_4, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_2 = t_0.view(t_2, (- 1), 4096) t_2 = self.l_14(t_2) t_2 = self.l_15(t_2) t_2 = (t_1 + t_2) t_1 = self.l_16(t_2) t_1 = self.l_17(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_18(t_1) return list(flatten((x0, t_2, t_1))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition12(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:12'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1] self.lookup = {'l_0': 'encoder.15.1.DenseReluDense.wo', 'l_1': 'encoder.15.1.dropout', 'l_2': 'encoder.16.0.layer_norm'} self.to(self.device) def forward(self, *args): (x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1) t_0 = self.l_1(t_0) t_0 = (x0 + t_0) t_1 = self.l_2(t_0) t_2 = t_1.size() t_2 = t_2[0] return list(flatten((t_0, t_1, t_2))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition13(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:13'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1] self.lookup = {'l_0': 'encoder.16.0.SelfAttention.q', 'l_1': 'encoder.16.0.SelfAttention.k', 'l_2': 'encoder.16.0.SelfAttention.v', 'l_3': 'encoder.16.0.SelfAttention.dropout', 'l_4': 'encoder.16.0.SelfAttention.o', 'l_5': 'encoder.16.0.dropout', 'l_6': 'encoder.16.1.layer_norm', 'l_7': 'encoder.16.1.DenseReluDense.wi', 'l_8': 'encoder.16.1.DenseReluDense.dropout', 'l_9': 'encoder.16.1.DenseReluDense.wo', 'l_10': 'encoder.16.1.dropout', 'l_11': 'encoder.17.0.layer_norm', 'l_12': 'encoder.17.0.SelfAttention.q', 'l_13': 'encoder.17.0.SelfAttention.k'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x2) t_1 = self.l_1(x2) t_2 = self.l_2(x2) t_0 = t_0.view(x3, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = t_1.view(x3, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_2 = t_2.view(x3, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_1 = t_1.transpose(3, 2) t_1 = torch.matmul(t_0, t_1) t_1 += x0 t_0 = t_1.float() t_0 = torch.nn.functional.softmax(t_0, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_0.type_as(t_1) t_1 = self.l_3(t_1) t_2 = torch.matmul(t_1, t_2) t_2 = t_2.transpose(1, 2) t_2 = t_2.contiguous() t_2 = t_2.view(x3, (- 1), 4096) t_2 = self.l_4(t_2) t_2 = self.l_5(t_2) t_2 = (x1 + t_2) t_1 = self.l_6(t_2) t_1 = self.l_7(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_8(t_1) t_1 = self.l_9(t_1) t_1 = self.l_10(t_1) t_1 = (t_2 + t_1) t_2 = self.l_11(t_1) t_0 = t_2.size() t_3 = self.l_12(t_2) t_4 = self.l_13(t_2) t_0 = t_0[0] t_3 = t_3.view(t_0, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_0, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_3, t_4) t_4 += x0 return list(flatten((x0, t_1, t_2, t_0, t_4))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition14(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:14'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1] self.lookup = {'l_0': 'encoder.17.0.SelfAttention.v', 'l_1': 'encoder.17.0.SelfAttention.dropout', 'l_2': 'encoder.17.0.SelfAttention.o', 'l_3': 'encoder.17.0.dropout', 'l_4': 'encoder.17.1.layer_norm', 'l_5': 'encoder.17.1.DenseReluDense.wi', 'l_6': 'encoder.17.1.DenseReluDense.dropout', 'l_7': 'encoder.17.1.DenseReluDense.wo', 'l_8': 'encoder.17.1.dropout', 'l_9': 'encoder.18.0.layer_norm', 'l_10': 'encoder.18.0.SelfAttention.q', 'l_11': 'encoder.18.0.SelfAttention.k', 'l_12': 'encoder.18.0.SelfAttention.v'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4) = unflatten(args, self.input_structure) t_0 = self.l_0(x2) t_0 = t_0.view(x3, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = x4.float() t_1 = torch.nn.functional.softmax(t_1, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_1.type_as(x4) t_1 = self.l_1(t_1) t_0 = torch.matmul(t_1, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_0 = t_0.view(x3, (- 1), 4096) t_0 = self.l_2(t_0) t_0 = self.l_3(t_0) t_0 = (x1 + t_0) t_1 = self.l_4(t_0) t_1 = self.l_5(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_6(t_1) t_1 = self.l_7(t_1) t_1 = self.l_8(t_1) t_1 = (t_0 + t_1) t_0 = self.l_9(t_1) t_2 = t_0.size() t_3 = self.l_10(t_0) t_4 = self.l_11(t_0) t_0 = self.l_12(t_0) t_2 = t_2[0] t_3 = t_3.view(t_2, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_2, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_0 = t_0.view(t_2, (- 1), 32, 128) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_3, t_4) t_4 += x0 return list(flatten((x0, t_1, t_2, t_0, t_4))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition15(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:15'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1] self.lookup = {'l_0': 'encoder.18.0.SelfAttention.dropout', 'l_1': 'encoder.18.0.SelfAttention.o', 'l_2': 'encoder.18.0.dropout', 'l_3': 'encoder.18.1.layer_norm', 'l_4': 'encoder.18.1.DenseReluDense.wi', 'l_5': 'encoder.18.1.DenseReluDense.dropout', 'l_6': 'encoder.18.1.DenseReluDense.wo', 'l_7': 'encoder.18.1.dropout', 'l_8': 'encoder.19.0.layer_norm', 'l_9': 'encoder.19.0.SelfAttention.q', 'l_10': 'encoder.19.0.SelfAttention.k', 'l_11': 'encoder.19.0.SelfAttention.v', 'l_12': 'encoder.19.0.SelfAttention.dropout'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4) = unflatten(args, self.input_structure) t_0 = x3.transpose(1, 2) t_1 = x4.float() t_1 = torch.nn.functional.softmax(t_1, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_1.type_as(x4) t_1 = self.l_0(t_1) t_0 = torch.matmul(t_1, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_0 = t_0.view(x2, (- 1), 4096) t_0 = self.l_1(t_0) t_0 = self.l_2(t_0) t_0 = (x1 + t_0) t_1 = self.l_3(t_0) t_1 = self.l_4(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_5(t_1) t_1 = self.l_6(t_1) t_1 = self.l_7(t_1) t_1 = (t_0 + t_1) t_0 = self.l_8(t_1) t_2 = t_0.size() t_3 = self.l_9(t_0) t_4 = self.l_10(t_0) t_0 = self.l_11(t_0) t_2 = t_2[0] t_3 = t_3.view(t_2, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_2, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_0 = t_0.view(t_2, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_3, t_4) t_4 += x0 t_3 = t_4.float() t_3 = torch.nn.functional.softmax(t_3, dim=(- 1), _stacklevel=3, dtype=None) t_4 = t_3.type_as(t_4) t_4 = self.l_12(t_4) return list(flatten((x0, t_1, t_2, t_0, t_4))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition16(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:16'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1] self.lookup = {'l_0': 'encoder.19.0.SelfAttention.o', 'l_1': 'encoder.19.0.dropout', 'l_2': 'encoder.19.1.layer_norm', 'l_3': 'encoder.19.1.DenseReluDense.wi', 'l_4': 'encoder.19.1.DenseReluDense.dropout', 'l_5': 'encoder.19.1.DenseReluDense.wo', 'l_6': 'encoder.19.1.dropout', 'l_7': 'encoder.20.0.layer_norm', 'l_8': 'encoder.20.0.SelfAttention.q', 'l_9': 'encoder.20.0.SelfAttention.k', 'l_10': 'encoder.20.0.SelfAttention.v'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = torch.matmul(x3, x2) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_0 = t_0.view(x1, (- 1), 4096) t_0 = self.l_0(t_0) t_0 = self.l_1(t_0) t_0 = (x0 + t_0) t_1 = self.l_2(t_0) t_1 = self.l_3(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_4(t_1) t_1 = self.l_5(t_1) t_1 = self.l_6(t_1) t_1 = (t_0 + t_1) t_0 = self.l_7(t_1) t_2 = t_0.size() t_3 = self.l_8(t_0) t_4 = self.l_9(t_0) t_0 = self.l_10(t_0) t_2 = t_2[0] t_3 = t_3.view(t_2, (- 1), 32, 128) t_4 = t_4.view(t_2, (- 1), 32, 128) t_0 = t_0.view(t_2, (- 1), 32, 128) return list(flatten((t_1, t_2, t_3, t_4, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition17(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:17'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'encoder.20.0.SelfAttention.dropout', 'l_1': 'encoder.20.0.SelfAttention.o', 'l_2': 'encoder.20.0.dropout', 'l_3': 'encoder.20.1.layer_norm', 'l_4': 'encoder.20.1.DenseReluDense.wi', 'l_5': 'encoder.20.1.DenseReluDense.dropout', 'l_6': 'encoder.20.1.DenseReluDense.wo', 'l_7': 'encoder.20.1.dropout', 'l_8': 'encoder.21.0.layer_norm', 'l_9': 'encoder.21.0.SelfAttention.q', 'l_10': 'encoder.21.0.SelfAttention.k', 'l_11': 'encoder.21.0.SelfAttention.v', 'l_12': 'encoder.21.0.SelfAttention.dropout'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4, x5) = unflatten(args, self.input_structure) t_0 = x3.transpose(1, 2) t_1 = x4.transpose(1, 2) t_2 = x5.transpose(1, 2) t_1 = t_1.transpose(3, 2) t_1 = torch.matmul(t_0, t_1) t_1 += x0 t_0 = t_1.float() t_0 = torch.nn.functional.softmax(t_0, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_0.type_as(t_1) t_1 = self.l_0(t_1) t_2 = torch.matmul(t_1, t_2) t_2 = t_2.transpose(1, 2) t_2 = t_2.contiguous() t_2 = t_2.view(x2, (- 1), 4096) t_2 = self.l_1(t_2) t_2 = self.l_2(t_2) t_2 = (x1 + t_2) t_1 = self.l_3(t_2) t_1 = self.l_4(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_5(t_1) t_1 = self.l_6(t_1) t_1 = self.l_7(t_1) t_1 = (t_2 + t_1) t_2 = self.l_8(t_1) t_0 = t_2.size() t_3 = self.l_9(t_2) t_4 = self.l_10(t_2) t_2 = self.l_11(t_2) t_0 = t_0[0] t_3 = t_3.view(t_0, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_0, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_2 = t_2.view(t_0, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_3, t_4) t_4 += x0 t_3 = t_4.float() t_3 = torch.nn.functional.softmax(t_3, dim=(- 1), _stacklevel=3, dtype=None) t_4 = t_3.type_as(t_4) t_4 = self.l_12(t_4) t_2 = torch.matmul(t_4, t_2) t_2 = t_2.transpose(1, 2) t_2 = t_2.contiguous() return list(flatten((x0, t_1, t_0, t_2))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition18(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerFF[1]/T5LayerNorm[layer_norm]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:18'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1] self.lookup = {'l_0': 'encoder.21.0.SelfAttention.o', 'l_1': 'encoder.21.0.dropout', 'l_2': 'encoder.21.1.layer_norm', 'l_3': 'encoder.21.1.DenseReluDense.wi', 'l_4': 'encoder.21.1.DenseReluDense.dropout', 'l_5': 'encoder.21.1.DenseReluDense.wo', 'l_6': 'encoder.21.1.dropout', 'l_7': 'encoder.22.0.layer_norm', 'l_8': 'encoder.22.0.SelfAttention.q', 'l_9': 'encoder.22.0.SelfAttention.k', 'l_10': 'encoder.22.0.SelfAttention.v', 'l_11': 'encoder.22.0.SelfAttention.dropout', 'l_12': 'encoder.22.0.SelfAttention.o', 'l_13': 'encoder.22.0.dropout', 'l_14': 'encoder.22.1.layer_norm'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = x3.view(x2, (- 1), 4096) t_0 = self.l_0(t_0) t_0 = self.l_1(t_0) t_0 = (x1 + t_0) t_1 = self.l_2(t_0) t_1 = self.l_3(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_4(t_1) t_1 = self.l_5(t_1) t_1 = self.l_6(t_1) t_1 = (t_0 + t_1) t_0 = self.l_7(t_1) t_2 = t_0.size() t_3 = self.l_8(t_0) t_4 = self.l_9(t_0) t_0 = self.l_10(t_0) t_2 = t_2[0] t_3 = t_3.view(t_2, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_2, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_0 = t_0.view(t_2, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_3, t_4) t_4 += x0 t_3 = t_4.float() t_3 = torch.nn.functional.softmax(t_3, dim=(- 1), _stacklevel=3, dtype=None) t_4 = t_3.type_as(t_4) t_4 = self.l_11(t_4) t_0 = torch.matmul(t_4, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_2 = t_0.view(t_2, (- 1), 4096) t_2 = self.l_12(t_2) t_2 = self.l_13(t_2) t_2 = (t_1 + t_2) t_1 = self.l_14(t_2) return list(flatten((x0, t_2, t_1))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition19(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:19'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1] self.lookup = {'l_0': 'encoder.22.1.DenseReluDense.wi', 'l_1': 'encoder.22.1.DenseReluDense.dropout', 'l_2': 'encoder.22.1.DenseReluDense.wo', 'l_3': 'encoder.22.1.dropout', 'l_4': 'encoder.23.0.layer_norm', 'l_5': 'encoder.23.0.SelfAttention.q', 'l_6': 'encoder.23.0.SelfAttention.k'} self.to(self.device) def forward(self, *args): (x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1) t_0 = torch.nn.functional.relu(t_0, inplace=False) t_0 = self.l_1(t_0) t_0 = self.l_2(t_0) t_0 = self.l_3(t_0) t_0 = (x0 + t_0) t_1 = self.l_4(t_0) t_2 = t_1.size() t_3 = self.l_5(t_1) t_4 = self.l_6(t_1) t_2 = t_2[0] return list(flatten((t_0, t_1, t_3, t_4, t_2))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition20(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerFF[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerFF[1]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]/T5LayerFF[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5LayerNorm[final_layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Embedding[relative_attention_bias]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:20'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'encoder.23.0.SelfAttention.v', 'l_1': 'encoder.23.0.SelfAttention.dropout', 'l_2': 'encoder.23.0.SelfAttention.o', 'l_3': 'encoder.23.0.dropout', 'l_4': 'encoder.23.1.layer_norm', 'l_5': 'encoder.23.1.DenseReluDense.wi', 'l_6': 'encoder.23.1.DenseReluDense.dropout', 'l_7': 'encoder.23.1.DenseReluDense.wo', 'l_8': 'encoder.23.1.dropout', 'l_9': 'encoder.final_layer_norm', 'l_10': 'encoder.dropout', 'l_11': 'decoder.0.0.SelfAttention.dropout', 'l_12': 'decoder.0.0.SelfAttention.o', 'l_13': 'decoder.0.0.dropout', 'l_14': 'decoder.0.1.layer_norm', 'l_15': 'decoder.0.1.EncDecAttention.q', 'l_16': 'decoder.0.1.EncDecAttention.k', 'l_17': 'decoder.0.1.EncDecAttention.v', 'l_18': 'decoder.0.1.EncDecAttention.relative_attention_bias', 'l_19': 'decoder.1.1.EncDecAttention.k', 'l_20': 'decoder.7.1.EncDecAttention.k', 'l_21': 'decoder.12.1.EncDecAttention.v', 'l_22': 'decoder.18.1.EncDecAttention.k', 'l_23': 'decoder.18.1.EncDecAttention.v', 'l_24': 'decoder.19.1.EncDecAttention.k'} self.to(self.device) def forward(self, *args): (inverted_encoder_attention_mask, x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) = unflatten(args, self.input_structure) t_0 = self.l_0(x2) t_1 = x3.view(x5, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_2 = x4.view(x5, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_0 = t_0.view(x5, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_2 = t_2.transpose(3, 2) t_2 = torch.matmul(t_1, t_2) t_2 += x0 t_1 = t_2.float() t_1 = torch.nn.functional.softmax(t_1, dim=(- 1), _stacklevel=3, dtype=None) t_2 = t_1.type_as(t_2) t_2 = self.l_1(t_2) t_0 = torch.matmul(t_2, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_0 = t_0.view(x5, (- 1), 4096) t_0 = self.l_2(t_0) t_0 = self.l_3(t_0) t_0 = (x1 + t_0) t_2 = self.l_4(t_0) t_2 = self.l_5(t_2) t_2 = torch.nn.functional.relu(t_2, inplace=False) t_2 = self.l_6(t_2) t_2 = self.l_7(t_2) t_2 = self.l_8(t_2) t_2 = (t_0 + t_2) t_2 = self.l_9(t_2) t_2 = self.l_10(t_2) t_0 = self.l_16(t_2) t_1 = self.l_17(t_2) t_3 = self.l_19(t_2) t_4 = self.l_20(t_2) t_5 = self.l_21(t_2) t_6 = self.l_22(t_2) t_7 = self.l_23(t_2) t_8 = self.l_24(t_2) t_9 = x10.type_as(x9) t_9 = self.l_11(t_9) t_9 = torch.matmul(t_9, x8) t_9 = t_9.transpose(1, 2) t_9 = t_9.contiguous() t_9 = t_9.view(x7, (- 1), 4096) t_9 = self.l_12(t_9) t_9 = self.l_13(t_9) t_9 = (x6 + t_9) t_10 = self.l_14(t_9) t_11 = t_10.size() t_10 = self.l_15(t_10) t_12 = t_11[0] t_11 = t_11[1] t_13 = t_2.size(1) t_10 = t_10.view(t_12, (- 1), 32, 128) t_10 = t_10.transpose(1, 2) t_0 = t_0.view(t_12, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = t_1.view(t_12, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_0 = t_0.transpose(3, 2) t_0 = torch.matmul(t_10, t_0) t_11 = torch.arange(t_11, dtype=torch.int64, device=self.device) t_11 = t_11[(slice(None, None, None), None)] t_13 = torch.arange(t_13, dtype=torch.int64, device=self.device) t_13 = t_13[(None, slice(None, None, None))] t_11 = (t_13 - t_11) t_11 = (- t_11) t_13 = torch.zeros_like(t_11) t_13 = torch.max(t_11, t_13) t_11 = t_13.float() t_10 = (t_13 < 16) t_11 = (t_11 / 16) t_11 = torch.log(t_11) t_14 = math.log(8.0) t_14 = (t_11 / t_14) t_14 = (t_14 * 16) t_14 = t_14.to(torch.int64) t_14 = (16 + t_14) t_11 = torch.full_like(t_14, 31) t_11 = torch.min(t_14, t_11) t_11 = torch.where(t_10, t_13, t_11) t_11 = (0 + t_11) t_11 = t_11.to(self.device) t_11 = self.l_18(t_11) t_11 = t_11.permute([2, 0, 1]) t_11 = t_11.unsqueeze(0) t_11 = (t_11 + inverted_encoder_attention_mask) t_0 += t_11 t_13 = t_0.float() return list(flatten((t_2, t_3, t_4, t_5, t_6, t_7, t_8, t_9, t_12, t_1, t_11, t_0, t_13))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition21(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:21'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.0.1.EncDecAttention.dropout', 'l_1': 'decoder.0.1.EncDecAttention.o', 'l_2': 'decoder.0.1.dropout', 'l_3': 'decoder.0.2.layer_norm', 'l_4': 'decoder.0.2.DenseReluDense.wi', 'l_5': 'decoder.0.2.DenseReluDense.dropout', 'l_6': 'decoder.0.2.DenseReluDense.wo', 'l_7': 'decoder.0.2.dropout', 'l_8': 'decoder.1.0.layer_norm', 'l_9': 'decoder.1.0.SelfAttention.q', 'l_10': 'decoder.1.0.SelfAttention.k', 'l_11': 'decoder.1.0.SelfAttention.v', 'l_12': 'decoder.1.0.SelfAttention.dropout', 'l_13': 'decoder.1.0.SelfAttention.o', 'l_14': 'decoder.1.0.dropout', 'l_15': 'decoder.1.1.layer_norm', 'l_16': 'decoder.1.1.EncDecAttention.q', 'l_17': 'decoder.1.1.EncDecAttention.v', 'l_18': 'decoder.1.1.EncDecAttention.dropout', 'l_19': 'decoder.1.1.EncDecAttention.o', 'l_20': 'decoder.1.1.dropout', 'l_21': 'decoder.1.2.layer_norm', 'l_22': 'decoder.1.2.DenseReluDense.wi', 'l_23': 'decoder.1.2.DenseReluDense.dropout', 'l_24': 'decoder.1.2.DenseReluDense.wo', 'l_25': 'decoder.1.2.dropout', 'l_26': 'decoder.2.0.layer_norm', 'l_27': 'decoder.2.0.SelfAttention.q', 'l_28': 'decoder.2.0.SelfAttention.k', 'l_29': 'decoder.2.0.SelfAttention.v', 'l_30': 'decoder.2.0.SelfAttention.dropout', 'l_31': 'decoder.2.0.SelfAttention.o', 'l_32': 'decoder.2.0.dropout', 'l_33': 'decoder.2.1.layer_norm', 'l_34': 'decoder.2.1.EncDecAttention.q', 'l_35': 'decoder.2.1.EncDecAttention.k', 'l_36': 'decoder.2.1.EncDecAttention.v', 'l_37': 'decoder.2.1.EncDecAttention.dropout', 'l_38': 'decoder.2.1.EncDecAttention.o', 'l_39': 'decoder.2.1.dropout', 'l_40': 'decoder.2.2.layer_norm', 'l_41': 'decoder.2.2.DenseReluDense.wi', 'l_42': 'decoder.2.2.DenseReluDense.dropout', 'l_43': 'decoder.2.2.DenseReluDense.wo', 'l_44': 'decoder.2.2.dropout', 'l_45': 'decoder.3.0.layer_norm', 'l_46': 'decoder.3.0.SelfAttention.q', 'l_47': 'decoder.3.0.SelfAttention.k', 'l_48': 'decoder.3.0.SelfAttention.v', 'l_49': 'decoder.3.0.SelfAttention.dropout', 'l_50': 'decoder.3.0.SelfAttention.o', 'l_51': 'decoder.3.0.dropout', 'l_52': 'decoder.3.1.layer_norm', 'l_53': 'decoder.3.1.EncDecAttention.q', 'l_54': 'decoder.3.1.EncDecAttention.k', 'l_55': 'decoder.3.1.EncDecAttention.v', 'l_56': 'decoder.3.1.EncDecAttention.dropout', 'l_57': 'decoder.3.1.EncDecAttention.o', 'l_58': 'decoder.3.1.dropout', 'l_59': 'decoder.3.2.layer_norm', 'l_60': 'decoder.3.2.DenseReluDense.wi', 'l_61': 'decoder.3.2.DenseReluDense.dropout', 'l_62': 'decoder.3.2.DenseReluDense.wo', 'l_63': 'decoder.3.2.dropout', 'l_64': 'decoder.4.0.layer_norm', 'l_65': 'decoder.4.0.SelfAttention.q', 'l_66': 'decoder.4.0.SelfAttention.k', 'l_67': 'decoder.4.0.SelfAttention.v', 'l_68': 'decoder.4.0.SelfAttention.dropout', 'l_69': 'decoder.4.0.SelfAttention.o', 'l_70': 'decoder.4.0.dropout', 'l_71': 'decoder.4.1.layer_norm', 'l_72': 'decoder.4.1.EncDecAttention.q', 'l_73': 'decoder.4.1.EncDecAttention.k', 'l_74': 'decoder.4.1.EncDecAttention.v', 'l_75': 'decoder.4.1.EncDecAttention.dropout'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4, x5, x6, x7, x8) = unflatten(args, self.input_structure) t_0 = self.l_17(x0) t_1 = self.l_35(x0) t_2 = self.l_36(x0) t_3 = self.l_54(x0) t_4 = self.l_55(x0) t_5 = self.l_73(x0) t_6 = self.l_74(x0) t_7 = torch.nn.functional.softmax(x8, dim=(- 1), _stacklevel=3, dtype=None) t_7 = t_7.type_as(x7) t_7 = self.l_0(t_7) t_7 = torch.matmul(t_7, x5) t_7 = t_7.transpose(1, 2) t_7 = t_7.contiguous() t_7 = t_7.view(x4, (- 1), 4096) t_7 = self.l_1(t_7) t_7 = self.l_2(t_7) t_7 = (x3 + t_7) t_8 = self.l_3(t_7) t_8 = self.l_4(t_8) t_8 = torch.nn.functional.relu(t_8, inplace=False) t_8 = self.l_5(t_8) t_8 = self.l_6(t_8) t_8 = self.l_7(t_8) t_8 = (t_7 + t_8) t_7 = self.l_8(t_8) t_9 = t_7.size() t_10 = self.l_9(t_7) t_11 = self.l_10(t_7) t_7 = self.l_11(t_7) t_9 = t_9[0] t_10 = t_10.view(t_9, (- 1), 32, 128) t_10 = t_10.transpose(1, 2) t_11 = t_11.view(t_9, (- 1), 32, 128) t_11 = t_11.transpose(1, 2) t_7 = t_7.view(t_9, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_11 = t_11.transpose(3, 2) t_11 = torch.matmul(t_10, t_11) t_11 += x2 t_10 = t_11.float() t_10 = torch.nn.functional.softmax(t_10, dim=(- 1), _stacklevel=3, dtype=None) t_11 = t_10.type_as(t_11) t_11 = self.l_12(t_11) t_7 = torch.matmul(t_11, t_7) t_7 = t_7.transpose(1, 2) t_7 = t_7.contiguous() t_9 = t_7.view(t_9, (- 1), 4096) t_9 = self.l_13(t_9) t_9 = self.l_14(t_9) t_9 = (t_8 + t_9) t_8 = self.l_15(t_9) t_7 = t_8.size() t_8 = self.l_16(t_8) t_7 = t_7[0] t_8 = t_8.view(t_7, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_11 = x1.view(t_7, (- 1), 32, 128) t_11 = t_11.transpose(1, 2) t_0 = t_0.view(t_7, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_11 = t_11.transpose(3, 2) t_11 = torch.matmul(t_8, t_11) t_11 += x6 t_8 = t_11.float() t_8 = torch.nn.functional.softmax(t_8, dim=(- 1), _stacklevel=3, dtype=None) t_11 = t_8.type_as(t_11) t_11 = self.l_18(t_11) t_0 = torch.matmul(t_11, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_7 = t_0.view(t_7, (- 1), 4096) t_7 = self.l_19(t_7) t_7 = self.l_20(t_7) t_7 = (t_9 + t_7) t_9 = self.l_21(t_7) t_9 = self.l_22(t_9) t_9 = torch.nn.functional.relu(t_9, inplace=False) t_9 = self.l_23(t_9) t_9 = self.l_24(t_9) t_9 = self.l_25(t_9) t_9 = (t_7 + t_9) t_7 = self.l_26(t_9) t_0 = t_7.size() t_11 = self.l_27(t_7) t_8 = self.l_28(t_7) t_7 = self.l_29(t_7) t_0 = t_0[0] t_11 = t_11.view(t_0, (- 1), 32, 128) t_11 = t_11.transpose(1, 2) t_8 = t_8.view(t_0, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_7 = t_7.view(t_0, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_8 = t_8.transpose(3, 2) t_8 = torch.matmul(t_11, t_8) t_8 += x2 t_11 = t_8.float() t_11 = torch.nn.functional.softmax(t_11, dim=(- 1), _stacklevel=3, dtype=None) t_8 = t_11.type_as(t_8) t_8 = self.l_30(t_8) t_7 = torch.matmul(t_8, t_7) t_7 = t_7.transpose(1, 2) t_7 = t_7.contiguous() t_0 = t_7.view(t_0, (- 1), 4096) t_0 = self.l_31(t_0) t_0 = self.l_32(t_0) t_0 = (t_9 + t_0) t_9 = self.l_33(t_0) t_7 = t_9.size() t_9 = self.l_34(t_9) t_7 = t_7[0] t_9 = t_9.view(t_7, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_1 = t_1.view(t_7, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_2 = t_2.view(t_7, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_1 = t_1.transpose(3, 2) t_1 = torch.matmul(t_9, t_1) t_1 += x6 t_9 = t_1.float() t_9 = torch.nn.functional.softmax(t_9, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_9.type_as(t_1) t_1 = self.l_37(t_1) t_2 = torch.matmul(t_1, t_2) t_2 = t_2.transpose(1, 2) t_2 = t_2.contiguous() t_7 = t_2.view(t_7, (- 1), 4096) t_7 = self.l_38(t_7) t_7 = self.l_39(t_7) t_7 = (t_0 + t_7) t_0 = self.l_40(t_7) t_0 = self.l_41(t_0) t_0 = torch.nn.functional.relu(t_0, inplace=False) t_0 = self.l_42(t_0) t_0 = self.l_43(t_0) t_0 = self.l_44(t_0) t_0 = (t_7 + t_0) t_7 = self.l_45(t_0) t_2 = t_7.size() t_1 = self.l_46(t_7) t_9 = self.l_47(t_7) t_7 = self.l_48(t_7) t_2 = t_2[0] t_1 = t_1.view(t_2, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_9 = t_9.view(t_2, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_7 = t_7.view(t_2, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_9 = t_9.transpose(3, 2) t_9 = torch.matmul(t_1, t_9) t_9 += x2 t_1 = t_9.float() t_1 = torch.nn.functional.softmax(t_1, dim=(- 1), _stacklevel=3, dtype=None) t_9 = t_1.type_as(t_9) t_9 = self.l_49(t_9) t_7 = torch.matmul(t_9, t_7) t_7 = t_7.transpose(1, 2) t_7 = t_7.contiguous() t_2 = t_7.view(t_2, (- 1), 4096) t_2 = self.l_50(t_2) t_2 = self.l_51(t_2) t_2 = (t_0 + t_2) t_0 = self.l_52(t_2) t_7 = t_0.size() t_0 = self.l_53(t_0) t_7 = t_7[0] t_0 = t_0.view(t_7, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_3 = t_3.view(t_7, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_7, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_3 = t_3.transpose(3, 2) t_3 = torch.matmul(t_0, t_3) t_3 += x6 t_0 = t_3.float() t_0 = torch.nn.functional.softmax(t_0, dim=(- 1), _stacklevel=3, dtype=None) t_3 = t_0.type_as(t_3) t_3 = self.l_56(t_3) t_4 = torch.matmul(t_3, t_4) t_4 = t_4.transpose(1, 2) t_4 = t_4.contiguous() t_7 = t_4.view(t_7, (- 1), 4096) t_7 = self.l_57(t_7) t_7 = self.l_58(t_7) t_7 = (t_2 + t_7) t_2 = self.l_59(t_7) t_2 = self.l_60(t_2) t_2 = torch.nn.functional.relu(t_2, inplace=False) t_2 = self.l_61(t_2) t_2 = self.l_62(t_2) t_2 = self.l_63(t_2) t_2 = (t_7 + t_2) t_7 = self.l_64(t_2) t_4 = t_7.size() t_3 = self.l_65(t_7) t_0 = self.l_66(t_7) t_7 = self.l_67(t_7) t_4 = t_4[0] t_3 = t_3.view(t_4, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_0 = t_0.view(t_4, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_7 = t_7.view(t_4, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_0 = t_0.transpose(3, 2) t_0 = torch.matmul(t_3, t_0) t_0 += x2 t_3 = t_0.float() t_3 = torch.nn.functional.softmax(t_3, dim=(- 1), _stacklevel=3, dtype=None) t_0 = t_3.type_as(t_0) t_0 = self.l_68(t_0) t_7 = torch.matmul(t_0, t_7) t_7 = t_7.transpose(1, 2) t_7 = t_7.contiguous() t_4 = t_7.view(t_4, (- 1), 4096) t_4 = self.l_69(t_4) t_4 = self.l_70(t_4) t_4 = (t_2 + t_4) t_2 = self.l_71(t_4) t_7 = t_2.size() t_2 = self.l_72(t_2) t_7 = t_7[0] t_2 = t_2.view(t_7, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_5 = t_5.view(t_7, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_6 = t_6.view(t_7, (- 1), 32, 128) t_6 = t_6.transpose(1, 2) t_5 = t_5.transpose(3, 2) t_5 = torch.matmul(t_2, t_5) t_5 += x6 t_2 = t_5.float() t_2 = torch.nn.functional.softmax(t_2, dim=(- 1), _stacklevel=3, dtype=None) t_5 = t_2.type_as(t_5) t_5 = self.l_75(t_5) t_6 = torch.matmul(t_5, t_6) t_6 = t_6.transpose(1, 2) t_6 = t_6.contiguous() return list(flatten((x0, x2, x6, t_4, t_7, t_6))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition22(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:22'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.4.1.EncDecAttention.o', 'l_1': 'decoder.4.1.dropout', 'l_2': 'decoder.4.2.layer_norm', 'l_3': 'decoder.4.2.DenseReluDense.wi', 'l_4': 'decoder.4.2.DenseReluDense.dropout', 'l_5': 'decoder.4.2.DenseReluDense.wo', 'l_6': 'decoder.4.2.dropout', 'l_7': 'decoder.5.0.layer_norm', 'l_8': 'decoder.5.0.SelfAttention.q', 'l_9': 'decoder.5.0.SelfAttention.k', 'l_10': 'decoder.5.0.SelfAttention.v', 'l_11': 'decoder.5.0.SelfAttention.dropout', 'l_12': 'decoder.5.0.SelfAttention.o', 'l_13': 'decoder.5.0.dropout', 'l_14': 'decoder.5.1.layer_norm', 'l_15': 'decoder.5.1.EncDecAttention.q', 'l_16': 'decoder.5.1.EncDecAttention.k', 'l_17': 'decoder.5.1.EncDecAttention.v', 'l_18': 'decoder.5.1.EncDecAttention.dropout', 'l_19': 'decoder.5.1.EncDecAttention.o', 'l_20': 'decoder.5.1.dropout', 'l_21': 'decoder.5.2.layer_norm', 'l_22': 'decoder.5.2.DenseReluDense.wi', 'l_23': 'decoder.5.2.DenseReluDense.dropout', 'l_24': 'decoder.5.2.DenseReluDense.wo', 'l_25': 'decoder.5.2.dropout', 'l_26': 'decoder.6.0.layer_norm', 'l_27': 'decoder.6.0.SelfAttention.q', 'l_28': 'decoder.6.0.SelfAttention.k', 'l_29': 'decoder.6.0.SelfAttention.v', 'l_30': 'decoder.6.0.SelfAttention.dropout', 'l_31': 'decoder.6.0.SelfAttention.o', 'l_32': 'decoder.6.0.dropout', 'l_33': 'decoder.6.1.layer_norm', 'l_34': 'decoder.6.1.EncDecAttention.q', 'l_35': 'decoder.6.1.EncDecAttention.k', 'l_36': 'decoder.6.1.EncDecAttention.v', 'l_37': 'decoder.6.1.EncDecAttention.dropout', 'l_38': 'decoder.6.1.EncDecAttention.o', 'l_39': 'decoder.6.1.dropout', 'l_40': 'decoder.6.2.layer_norm', 'l_41': 'decoder.6.2.DenseReluDense.wi', 'l_42': 'decoder.6.2.DenseReluDense.dropout', 'l_43': 'decoder.6.2.DenseReluDense.wo'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4, x5) = unflatten(args, self.input_structure) t_0 = self.l_16(x0) t_1 = self.l_17(x0) t_2 = self.l_35(x0) t_3 = self.l_36(x0) t_4 = x5.view(x4, (- 1), 4096) t_4 = self.l_0(t_4) t_4 = self.l_1(t_4) t_4 = (x3 + t_4) t_5 = self.l_2(t_4) t_5 = self.l_3(t_5) t_5 = torch.nn.functional.relu(t_5, inplace=False) t_5 = self.l_4(t_5) t_5 = self.l_5(t_5) t_5 = self.l_6(t_5) t_5 = (t_4 + t_5) t_4 = self.l_7(t_5) t_6 = t_4.size() t_7 = self.l_8(t_4) t_8 = self.l_9(t_4) t_4 = self.l_10(t_4) t_6 = t_6[0] t_7 = t_7.view(t_6, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_8 = t_8.view(t_6, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_4 = t_4.view(t_6, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_8 = t_8.transpose(3, 2) t_8 = torch.matmul(t_7, t_8) t_8 += x1 t_7 = t_8.float() t_7 = torch.nn.functional.softmax(t_7, dim=(- 1), _stacklevel=3, dtype=None) t_8 = t_7.type_as(t_8) t_8 = self.l_11(t_8) t_4 = torch.matmul(t_8, t_4) t_4 = t_4.transpose(1, 2) t_4 = t_4.contiguous() t_6 = t_4.view(t_6, (- 1), 4096) t_6 = self.l_12(t_6) t_6 = self.l_13(t_6) t_6 = (t_5 + t_6) t_5 = self.l_14(t_6) t_4 = t_5.size() t_5 = self.l_15(t_5) t_4 = t_4[0] t_5 = t_5.view(t_4, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_0 = t_0.view(t_4, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = t_1.view(t_4, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_0 = t_0.transpose(3, 2) t_0 = torch.matmul(t_5, t_0) t_0 += x2 t_5 = t_0.float() t_5 = torch.nn.functional.softmax(t_5, dim=(- 1), _stacklevel=3, dtype=None) t_0 = t_5.type_as(t_0) t_0 = self.l_18(t_0) t_1 = torch.matmul(t_0, t_1) t_1 = t_1.transpose(1, 2) t_1 = t_1.contiguous() t_4 = t_1.view(t_4, (- 1), 4096) t_4 = self.l_19(t_4) t_4 = self.l_20(t_4) t_4 = (t_6 + t_4) t_6 = self.l_21(t_4) t_6 = self.l_22(t_6) t_6 = torch.nn.functional.relu(t_6, inplace=False) t_6 = self.l_23(t_6) t_6 = self.l_24(t_6) t_6 = self.l_25(t_6) t_6 = (t_4 + t_6) t_4 = self.l_26(t_6) t_1 = t_4.size() t_0 = self.l_27(t_4) t_5 = self.l_28(t_4) t_4 = self.l_29(t_4) t_1 = t_1[0] t_0 = t_0.view(t_1, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_5 = t_5.view(t_1, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_4 = t_4.view(t_1, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_5 = t_5.transpose(3, 2) t_5 = torch.matmul(t_0, t_5) t_5 += x1 t_0 = t_5.float() t_0 = torch.nn.functional.softmax(t_0, dim=(- 1), _stacklevel=3, dtype=None) t_5 = t_0.type_as(t_5) t_5 = self.l_30(t_5) t_4 = torch.matmul(t_5, t_4) t_4 = t_4.transpose(1, 2) t_4 = t_4.contiguous() t_1 = t_4.view(t_1, (- 1), 4096) t_1 = self.l_31(t_1) t_1 = self.l_32(t_1) t_1 = (t_6 + t_1) t_6 = self.l_33(t_1) t_4 = t_6.size() t_6 = self.l_34(t_6) t_4 = t_4[0] t_6 = t_6.view(t_4, (- 1), 32, 128) t_6 = t_6.transpose(1, 2) t_2 = t_2.view(t_4, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_3 = t_3.view(t_4, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_2 = t_2.transpose(3, 2) t_2 = torch.matmul(t_6, t_2) t_2 += x2 t_6 = t_2.float() t_6 = torch.nn.functional.softmax(t_6, dim=(- 1), _stacklevel=3, dtype=None) t_2 = t_6.type_as(t_2) t_2 = self.l_37(t_2) t_3 = torch.matmul(t_2, t_3) t_3 = t_3.transpose(1, 2) t_3 = t_3.contiguous() t_4 = t_3.view(t_4, (- 1), 4096) t_4 = self.l_38(t_4) t_4 = self.l_39(t_4) t_4 = (t_1 + t_4) t_1 = self.l_40(t_4) t_1 = self.l_41(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_42(t_1) t_1 = self.l_43(t_1) return list(flatten((x0, x1, x2, t_4, t_1))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition23(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:23'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.6.2.dropout', 'l_1': 'decoder.7.0.layer_norm', 'l_2': 'decoder.7.0.SelfAttention.q', 'l_3': 'decoder.7.0.SelfAttention.k', 'l_4': 'decoder.7.0.SelfAttention.v', 'l_5': 'decoder.7.0.SelfAttention.dropout', 'l_6': 'decoder.7.0.SelfAttention.o', 'l_7': 'decoder.7.0.dropout', 'l_8': 'decoder.7.1.layer_norm', 'l_9': 'decoder.7.1.EncDecAttention.q', 'l_10': 'decoder.7.1.EncDecAttention.v', 'l_11': 'decoder.7.1.EncDecAttention.dropout', 'l_12': 'decoder.7.1.EncDecAttention.o', 'l_13': 'decoder.7.1.dropout', 'l_14': 'decoder.7.2.layer_norm', 'l_15': 'decoder.7.2.DenseReluDense.wi', 'l_16': 'decoder.7.2.DenseReluDense.dropout', 'l_17': 'decoder.7.2.DenseReluDense.wo', 'l_18': 'decoder.7.2.dropout', 'l_19': 'decoder.8.0.layer_norm', 'l_20': 'decoder.8.0.SelfAttention.q', 'l_21': 'decoder.8.0.SelfAttention.k', 'l_22': 'decoder.8.0.SelfAttention.v', 'l_23': 'decoder.8.0.SelfAttention.dropout', 'l_24': 'decoder.8.0.SelfAttention.o', 'l_25': 'decoder.8.0.dropout', 'l_26': 'decoder.8.1.layer_norm', 'l_27': 'decoder.8.1.EncDecAttention.q', 'l_28': 'decoder.8.1.EncDecAttention.k', 'l_29': 'decoder.8.1.EncDecAttention.v', 'l_30': 'decoder.8.1.EncDecAttention.dropout', 'l_31': 'decoder.8.1.EncDecAttention.o', 'l_32': 'decoder.8.1.dropout', 'l_33': 'decoder.8.2.layer_norm', 'l_34': 'decoder.8.2.DenseReluDense.wi'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4, x5) = unflatten(args, self.input_structure) t_0 = self.l_10(x0) t_1 = self.l_28(x0) t_2 = self.l_29(x0) t_3 = self.l_0(x5) t_3 = (x4 + t_3) t_4 = self.l_1(t_3) t_5 = t_4.size() t_6 = self.l_2(t_4) t_7 = self.l_3(t_4) t_4 = self.l_4(t_4) t_5 = t_5[0] t_6 = t_6.view(t_5, (- 1), 32, 128) t_6 = t_6.transpose(1, 2) t_7 = t_7.view(t_5, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_4 = t_4.view(t_5, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_7 = t_7.transpose(3, 2) t_7 = torch.matmul(t_6, t_7) t_7 += x2 t_6 = t_7.float() t_6 = torch.nn.functional.softmax(t_6, dim=(- 1), _stacklevel=3, dtype=None) t_7 = t_6.type_as(t_7) t_7 = self.l_5(t_7) t_4 = torch.matmul(t_7, t_4) t_4 = t_4.transpose(1, 2) t_4 = t_4.contiguous() t_5 = t_4.view(t_5, (- 1), 4096) t_5 = self.l_6(t_5) t_5 = self.l_7(t_5) t_5 = (t_3 + t_5) t_3 = self.l_8(t_5) t_4 = t_3.size() t_3 = self.l_9(t_3) t_4 = t_4[0] t_3 = t_3.view(t_4, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_7 = x1.view(t_4, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_0 = t_0.view(t_4, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_7 = t_7.transpose(3, 2) t_7 = torch.matmul(t_3, t_7) t_7 += x3 t_3 = t_7.float() t_3 = torch.nn.functional.softmax(t_3, dim=(- 1), _stacklevel=3, dtype=None) t_7 = t_3.type_as(t_7) t_7 = self.l_11(t_7) t_0 = torch.matmul(t_7, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_4 = t_0.view(t_4, (- 1), 4096) t_4 = self.l_12(t_4) t_4 = self.l_13(t_4) t_4 = (t_5 + t_4) t_5 = self.l_14(t_4) t_5 = self.l_15(t_5) t_5 = torch.nn.functional.relu(t_5, inplace=False) t_5 = self.l_16(t_5) t_5 = self.l_17(t_5) t_5 = self.l_18(t_5) t_5 = (t_4 + t_5) t_4 = self.l_19(t_5) t_0 = t_4.size() t_7 = self.l_20(t_4) t_3 = self.l_21(t_4) t_4 = self.l_22(t_4) t_0 = t_0[0] t_7 = t_7.view(t_0, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_3 = t_3.view(t_0, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_0, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_3 = t_3.transpose(3, 2) t_3 = torch.matmul(t_7, t_3) t_3 += x2 t_7 = t_3.float() t_7 = torch.nn.functional.softmax(t_7, dim=(- 1), _stacklevel=3, dtype=None) t_3 = t_7.type_as(t_3) t_3 = self.l_23(t_3) t_4 = torch.matmul(t_3, t_4) t_4 = t_4.transpose(1, 2) t_4 = t_4.contiguous() t_0 = t_4.view(t_0, (- 1), 4096) t_0 = self.l_24(t_0) t_0 = self.l_25(t_0) t_0 = (t_5 + t_0) t_5 = self.l_26(t_0) t_4 = t_5.size() t_5 = self.l_27(t_5) t_4 = t_4[0] t_5 = t_5.view(t_4, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_1 = t_1.view(t_4, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_2 = t_2.view(t_4, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_1 = t_1.transpose(3, 2) t_1 = torch.matmul(t_5, t_1) t_1 += x3 t_5 = t_1.float() t_5 = torch.nn.functional.softmax(t_5, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_5.type_as(t_1) t_1 = self.l_30(t_1) t_2 = torch.matmul(t_1, t_2) t_2 = t_2.transpose(1, 2) t_2 = t_2.contiguous() t_4 = t_2.view(t_4, (- 1), 4096) t_4 = self.l_31(t_4) t_4 = self.l_32(t_4) t_4 = (t_0 + t_4) t_0 = self.l_33(t_4) t_0 = self.l_34(t_0) return list(flatten((x0, x2, x3, t_4, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition24(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:24'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.8.2.DenseReluDense.dropout', 'l_1': 'decoder.8.2.DenseReluDense.wo', 'l_2': 'decoder.8.2.dropout', 'l_3': 'decoder.9.0.layer_norm', 'l_4': 'decoder.9.0.SelfAttention.q', 'l_5': 'decoder.9.0.SelfAttention.k', 'l_6': 'decoder.9.0.SelfAttention.v', 'l_7': 'decoder.9.0.SelfAttention.dropout', 'l_8': 'decoder.9.0.SelfAttention.o', 'l_9': 'decoder.9.0.dropout', 'l_10': 'decoder.9.1.layer_norm', 'l_11': 'decoder.9.1.EncDecAttention.q', 'l_12': 'decoder.9.1.EncDecAttention.k', 'l_13': 'decoder.9.1.EncDecAttention.v', 'l_14': 'decoder.9.1.EncDecAttention.dropout', 'l_15': 'decoder.9.1.EncDecAttention.o', 'l_16': 'decoder.9.1.dropout', 'l_17': 'decoder.9.2.layer_norm', 'l_18': 'decoder.9.2.DenseReluDense.wi', 'l_19': 'decoder.9.2.DenseReluDense.dropout', 'l_20': 'decoder.9.2.DenseReluDense.wo', 'l_21': 'decoder.9.2.dropout', 'l_22': 'decoder.10.0.layer_norm', 'l_23': 'decoder.10.0.SelfAttention.q', 'l_24': 'decoder.10.0.SelfAttention.k', 'l_25': 'decoder.10.0.SelfAttention.v', 'l_26': 'decoder.10.0.SelfAttention.dropout', 'l_27': 'decoder.10.0.SelfAttention.o', 'l_28': 'decoder.10.0.dropout', 'l_29': 'decoder.10.1.layer_norm', 'l_30': 'decoder.10.1.EncDecAttention.q', 'l_31': 'decoder.10.1.EncDecAttention.k', 'l_32': 'decoder.10.1.EncDecAttention.v', 'l_33': 'decoder.10.1.EncDecAttention.dropout', 'l_34': 'decoder.10.1.EncDecAttention.o', 'l_35': 'decoder.10.1.dropout', 'l_36': 'decoder.10.2.layer_norm', 'l_37': 'decoder.10.2.DenseReluDense.wi', 'l_38': 'decoder.10.2.DenseReluDense.dropout', 'l_39': 'decoder.10.2.DenseReluDense.wo', 'l_40': 'decoder.10.2.dropout', 'l_41': 'decoder.11.0.layer_norm', 'l_42': 'decoder.11.0.SelfAttention.q', 'l_43': 'decoder.11.0.SelfAttention.k', 'l_44': 'decoder.11.0.SelfAttention.v', 'l_45': 'decoder.11.0.SelfAttention.dropout', 'l_46': 'decoder.11.0.SelfAttention.o', 'l_47': 'decoder.11.0.dropout', 'l_48': 'decoder.11.1.layer_norm', 'l_49': 'decoder.11.1.EncDecAttention.q', 'l_50': 'decoder.11.1.EncDecAttention.k', 'l_51': 'decoder.11.1.EncDecAttention.v', 'l_52': 'decoder.11.1.EncDecAttention.dropout', 'l_53': 'decoder.11.1.EncDecAttention.o', 'l_54': 'decoder.11.1.dropout', 'l_55': 'decoder.11.2.layer_norm', 'l_56': 'decoder.11.2.DenseReluDense.wi', 'l_57': 'decoder.11.2.DenseReluDense.dropout', 'l_58': 'decoder.11.2.DenseReluDense.wo', 'l_59': 'decoder.11.2.dropout', 'l_60': 'decoder.12.0.layer_norm', 'l_61': 'decoder.12.0.SelfAttention.q', 'l_62': 'decoder.12.0.SelfAttention.k', 'l_63': 'decoder.12.0.SelfAttention.v', 'l_64': 'decoder.12.0.SelfAttention.dropout', 'l_65': 'decoder.12.0.SelfAttention.o', 'l_66': 'decoder.12.0.dropout', 'l_67': 'decoder.12.1.layer_norm', 'l_68': 'decoder.12.1.EncDecAttention.q', 'l_69': 'decoder.12.1.EncDecAttention.k'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4) = unflatten(args, self.input_structure) t_0 = self.l_12(x0) t_1 = self.l_13(x0) t_2 = self.l_31(x0) t_3 = self.l_32(x0) t_4 = self.l_50(x0) t_5 = self.l_51(x0) t_6 = self.l_69(x0) t_7 = torch.nn.functional.relu(x4, inplace=False) t_7 = self.l_0(t_7) t_7 = self.l_1(t_7) t_7 = self.l_2(t_7) t_7 = (x3 + t_7) t_8 = self.l_3(t_7) t_9 = t_8.size() t_10 = self.l_4(t_8) t_11 = self.l_5(t_8) t_8 = self.l_6(t_8) t_9 = t_9[0] t_10 = t_10.view(t_9, (- 1), 32, 128) t_10 = t_10.transpose(1, 2) t_11 = t_11.view(t_9, (- 1), 32, 128) t_11 = t_11.transpose(1, 2) t_8 = t_8.view(t_9, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_11 = t_11.transpose(3, 2) t_11 = torch.matmul(t_10, t_11) t_11 += x1 t_10 = t_11.float() t_10 = torch.nn.functional.softmax(t_10, dim=(- 1), _stacklevel=3, dtype=None) t_11 = t_10.type_as(t_11) t_11 = self.l_7(t_11) t_8 = torch.matmul(t_11, t_8) t_8 = t_8.transpose(1, 2) t_8 = t_8.contiguous() t_9 = t_8.view(t_9, (- 1), 4096) t_9 = self.l_8(t_9) t_9 = self.l_9(t_9) t_9 = (t_7 + t_9) t_7 = self.l_10(t_9) t_8 = t_7.size() t_7 = self.l_11(t_7) t_8 = t_8[0] t_7 = t_7.view(t_8, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_0 = t_0.view(t_8, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = t_1.view(t_8, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_0 = t_0.transpose(3, 2) t_0 = torch.matmul(t_7, t_0) t_0 += x2 t_7 = t_0.float() t_7 = torch.nn.functional.softmax(t_7, dim=(- 1), _stacklevel=3, dtype=None) t_0 = t_7.type_as(t_0) t_0 = self.l_14(t_0) t_1 = torch.matmul(t_0, t_1) t_1 = t_1.transpose(1, 2) t_1 = t_1.contiguous() t_8 = t_1.view(t_8, (- 1), 4096) t_8 = self.l_15(t_8) t_8 = self.l_16(t_8) t_8 = (t_9 + t_8) t_9 = self.l_17(t_8) t_9 = self.l_18(t_9) t_9 = torch.nn.functional.relu(t_9, inplace=False) t_9 = self.l_19(t_9) t_9 = self.l_20(t_9) t_9 = self.l_21(t_9) t_9 = (t_8 + t_9) t_8 = self.l_22(t_9) t_1 = t_8.size() t_0 = self.l_23(t_8) t_7 = self.l_24(t_8) t_8 = self.l_25(t_8) t_1 = t_1[0] t_0 = t_0.view(t_1, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_7 = t_7.view(t_1, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_8 = t_8.view(t_1, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_7 = t_7.transpose(3, 2) t_7 = torch.matmul(t_0, t_7) t_7 += x1 t_0 = t_7.float() t_0 = torch.nn.functional.softmax(t_0, dim=(- 1), _stacklevel=3, dtype=None) t_7 = t_0.type_as(t_7) t_7 = self.l_26(t_7) t_8 = torch.matmul(t_7, t_8) t_8 = t_8.transpose(1, 2) t_8 = t_8.contiguous() t_1 = t_8.view(t_1, (- 1), 4096) t_1 = self.l_27(t_1) t_1 = self.l_28(t_1) t_1 = (t_9 + t_1) t_9 = self.l_29(t_1) t_8 = t_9.size() t_9 = self.l_30(t_9) t_8 = t_8[0] t_9 = t_9.view(t_8, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_2 = t_2.view(t_8, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_3 = t_3.view(t_8, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_2 = t_2.transpose(3, 2) t_2 = torch.matmul(t_9, t_2) t_2 += x2 t_9 = t_2.float() t_9 = torch.nn.functional.softmax(t_9, dim=(- 1), _stacklevel=3, dtype=None) t_2 = t_9.type_as(t_2) t_2 = self.l_33(t_2) t_3 = torch.matmul(t_2, t_3) t_3 = t_3.transpose(1, 2) t_3 = t_3.contiguous() t_8 = t_3.view(t_8, (- 1), 4096) t_8 = self.l_34(t_8) t_8 = self.l_35(t_8) t_8 = (t_1 + t_8) t_1 = self.l_36(t_8) t_1 = self.l_37(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_38(t_1) t_1 = self.l_39(t_1) t_1 = self.l_40(t_1) t_1 = (t_8 + t_1) t_8 = self.l_41(t_1) t_3 = t_8.size() t_2 = self.l_42(t_8) t_9 = self.l_43(t_8) t_8 = self.l_44(t_8) t_3 = t_3[0] t_2 = t_2.view(t_3, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_9 = t_9.view(t_3, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_8 = t_8.view(t_3, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_9 = t_9.transpose(3, 2) t_9 = torch.matmul(t_2, t_9) t_9 += x1 t_2 = t_9.float() t_2 = torch.nn.functional.softmax(t_2, dim=(- 1), _stacklevel=3, dtype=None) t_9 = t_2.type_as(t_9) t_9 = self.l_45(t_9) t_8 = torch.matmul(t_9, t_8) t_8 = t_8.transpose(1, 2) t_8 = t_8.contiguous() t_3 = t_8.view(t_3, (- 1), 4096) t_3 = self.l_46(t_3) t_3 = self.l_47(t_3) t_3 = (t_1 + t_3) t_1 = self.l_48(t_3) t_8 = t_1.size() t_1 = self.l_49(t_1) t_8 = t_8[0] t_1 = t_1.view(t_8, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_4 = t_4.view(t_8, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_5 = t_5.view(t_8, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_1, t_4) t_4 += x2 t_1 = t_4.float() t_1 = torch.nn.functional.softmax(t_1, dim=(- 1), _stacklevel=3, dtype=None) t_4 = t_1.type_as(t_4) t_4 = self.l_52(t_4) t_5 = torch.matmul(t_4, t_5) t_5 = t_5.transpose(1, 2) t_5 = t_5.contiguous() t_8 = t_5.view(t_8, (- 1), 4096) t_8 = self.l_53(t_8) t_8 = self.l_54(t_8) t_8 = (t_3 + t_8) t_3 = self.l_55(t_8) t_3 = self.l_56(t_3) t_3 = torch.nn.functional.relu(t_3, inplace=False) t_3 = self.l_57(t_3) t_3 = self.l_58(t_3) t_3 = self.l_59(t_3) t_3 = (t_8 + t_3) t_8 = self.l_60(t_3) t_5 = t_8.size() t_4 = self.l_61(t_8) t_1 = self.l_62(t_8) t_8 = self.l_63(t_8) t_5 = t_5[0] t_4 = t_4.view(t_5, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_1 = t_1.view(t_5, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_8 = t_8.view(t_5, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_1 = t_1.transpose(3, 2) t_1 = torch.matmul(t_4, t_1) t_1 += x1 t_4 = t_1.float() t_4 = torch.nn.functional.softmax(t_4, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_4.type_as(t_1) t_1 = self.l_64(t_1) t_8 = torch.matmul(t_1, t_8) t_8 = t_8.transpose(1, 2) t_8 = t_8.contiguous() t_5 = t_8.view(t_5, (- 1), 4096) t_5 = self.l_65(t_5) t_5 = self.l_66(t_5) t_5 = (t_3 + t_5) t_3 = self.l_67(t_5) t_8 = t_3.size() t_3 = self.l_68(t_3) t_8 = t_8[0] return list(flatten((x0, t_6, x1, x2, t_5, t_3, t_8))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition25(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerCrossAttention[1]/Dropout[dropout]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:25'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.12.1.EncDecAttention.dropout', 'l_1': 'decoder.12.1.EncDecAttention.o', 'l_2': 'decoder.12.1.dropout', 'l_3': 'decoder.12.2.layer_norm', 'l_4': 'decoder.12.2.DenseReluDense.wi', 'l_5': 'decoder.12.2.DenseReluDense.dropout', 'l_6': 'decoder.12.2.DenseReluDense.wo', 'l_7': 'decoder.12.2.dropout', 'l_8': 'decoder.13.0.layer_norm', 'l_9': 'decoder.13.0.SelfAttention.q', 'l_10': 'decoder.13.0.SelfAttention.k', 'l_11': 'decoder.13.0.SelfAttention.v', 'l_12': 'decoder.13.0.SelfAttention.dropout', 'l_13': 'decoder.13.0.SelfAttention.o', 'l_14': 'decoder.13.0.dropout', 'l_15': 'decoder.13.1.layer_norm', 'l_16': 'decoder.13.1.EncDecAttention.q', 'l_17': 'decoder.13.1.EncDecAttention.k', 'l_18': 'decoder.13.1.EncDecAttention.v', 'l_19': 'decoder.13.1.EncDecAttention.dropout', 'l_20': 'decoder.13.1.EncDecAttention.o', 'l_21': 'decoder.13.1.dropout', 'l_22': 'decoder.13.2.layer_norm', 'l_23': 'decoder.13.2.DenseReluDense.wi', 'l_24': 'decoder.13.2.DenseReluDense.dropout', 'l_25': 'decoder.13.2.DenseReluDense.wo', 'l_26': 'decoder.13.2.dropout', 'l_27': 'decoder.14.0.layer_norm', 'l_28': 'decoder.14.0.SelfAttention.q', 'l_29': 'decoder.14.0.SelfAttention.k', 'l_30': 'decoder.14.0.SelfAttention.v', 'l_31': 'decoder.14.0.SelfAttention.dropout', 'l_32': 'decoder.14.0.SelfAttention.o', 'l_33': 'decoder.14.0.dropout', 'l_34': 'decoder.14.1.layer_norm', 'l_35': 'decoder.14.1.EncDecAttention.q', 'l_36': 'decoder.14.1.EncDecAttention.k', 'l_37': 'decoder.14.1.EncDecAttention.v', 'l_38': 'decoder.14.1.EncDecAttention.dropout', 'l_39': 'decoder.14.1.EncDecAttention.o', 'l_40': 'decoder.14.1.dropout', 'l_41': 'decoder.14.2.layer_norm', 'l_42': 'decoder.14.2.DenseReluDense.wi', 'l_43': 'decoder.14.2.DenseReluDense.dropout', 'l_44': 'decoder.14.2.DenseReluDense.wo', 'l_45': 'decoder.14.2.dropout', 'l_46': 'decoder.15.0.layer_norm', 'l_47': 'decoder.15.0.SelfAttention.q', 'l_48': 'decoder.15.0.SelfAttention.k', 'l_49': 'decoder.15.0.SelfAttention.v', 'l_50': 'decoder.15.0.SelfAttention.dropout', 'l_51': 'decoder.15.0.SelfAttention.o', 'l_52': 'decoder.15.0.dropout', 'l_53': 'decoder.15.1.layer_norm', 'l_54': 'decoder.15.1.EncDecAttention.q', 'l_55': 'decoder.15.1.EncDecAttention.k', 'l_56': 'decoder.15.1.EncDecAttention.v', 'l_57': 'decoder.15.1.EncDecAttention.dropout', 'l_58': 'decoder.15.1.EncDecAttention.o', 'l_59': 'decoder.15.1.dropout'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4, x5, x6, x7) = unflatten(args, self.input_structure) t_0 = self.l_17(x0) t_1 = self.l_18(x0) t_2 = self.l_36(x0) t_3 = self.l_37(x0) t_4 = self.l_55(x0) t_5 = self.l_56(x0) t_6 = x6.view(x7, (- 1), 32, 128) t_6 = t_6.transpose(1, 2) t_7 = x1.view(x7, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_8 = x2.view(x7, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_7 = t_7.transpose(3, 2) t_7 = torch.matmul(t_6, t_7) t_7 += x4 t_6 = t_7.float() t_6 = torch.nn.functional.softmax(t_6, dim=(- 1), _stacklevel=3, dtype=None) t_7 = t_6.type_as(t_7) t_7 = self.l_0(t_7) t_8 = torch.matmul(t_7, t_8) t_8 = t_8.transpose(1, 2) t_8 = t_8.contiguous() t_8 = t_8.view(x7, (- 1), 4096) t_8 = self.l_1(t_8) t_8 = self.l_2(t_8) t_8 = (x5 + t_8) t_7 = self.l_3(t_8) t_7 = self.l_4(t_7) t_7 = torch.nn.functional.relu(t_7, inplace=False) t_7 = self.l_5(t_7) t_7 = self.l_6(t_7) t_7 = self.l_7(t_7) t_7 = (t_8 + t_7) t_8 = self.l_8(t_7) t_6 = t_8.size() t_9 = self.l_9(t_8) t_10 = self.l_10(t_8) t_8 = self.l_11(t_8) t_6 = t_6[0] t_9 = t_9.view(t_6, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_10 = t_10.view(t_6, (- 1), 32, 128) t_10 = t_10.transpose(1, 2) t_8 = t_8.view(t_6, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_10 = t_10.transpose(3, 2) t_10 = torch.matmul(t_9, t_10) t_10 += x3 t_9 = t_10.float() t_9 = torch.nn.functional.softmax(t_9, dim=(- 1), _stacklevel=3, dtype=None) t_10 = t_9.type_as(t_10) t_10 = self.l_12(t_10) t_8 = torch.matmul(t_10, t_8) t_8 = t_8.transpose(1, 2) t_8 = t_8.contiguous() t_6 = t_8.view(t_6, (- 1), 4096) t_6 = self.l_13(t_6) t_6 = self.l_14(t_6) t_6 = (t_7 + t_6) t_7 = self.l_15(t_6) t_8 = t_7.size() t_7 = self.l_16(t_7) t_8 = t_8[0] t_7 = t_7.view(t_8, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_0 = t_0.view(t_8, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = t_1.view(t_8, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_0 = t_0.transpose(3, 2) t_0 = torch.matmul(t_7, t_0) t_0 += x4 t_7 = t_0.float() t_7 = torch.nn.functional.softmax(t_7, dim=(- 1), _stacklevel=3, dtype=None) t_0 = t_7.type_as(t_0) t_0 = self.l_19(t_0) t_1 = torch.matmul(t_0, t_1) t_1 = t_1.transpose(1, 2) t_1 = t_1.contiguous() t_8 = t_1.view(t_8, (- 1), 4096) t_8 = self.l_20(t_8) t_8 = self.l_21(t_8) t_8 = (t_6 + t_8) t_6 = self.l_22(t_8) t_6 = self.l_23(t_6) t_6 = torch.nn.functional.relu(t_6, inplace=False) t_6 = self.l_24(t_6) t_6 = self.l_25(t_6) t_6 = self.l_26(t_6) t_6 = (t_8 + t_6) t_8 = self.l_27(t_6) t_1 = t_8.size() t_0 = self.l_28(t_8) t_7 = self.l_29(t_8) t_8 = self.l_30(t_8) t_1 = t_1[0] t_0 = t_0.view(t_1, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_7 = t_7.view(t_1, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_8 = t_8.view(t_1, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_7 = t_7.transpose(3, 2) t_7 = torch.matmul(t_0, t_7) t_7 += x3 t_0 = t_7.float() t_0 = torch.nn.functional.softmax(t_0, dim=(- 1), _stacklevel=3, dtype=None) t_7 = t_0.type_as(t_7) t_7 = self.l_31(t_7) t_8 = torch.matmul(t_7, t_8) t_8 = t_8.transpose(1, 2) t_8 = t_8.contiguous() t_1 = t_8.view(t_1, (- 1), 4096) t_1 = self.l_32(t_1) t_1 = self.l_33(t_1) t_1 = (t_6 + t_1) t_6 = self.l_34(t_1) t_8 = t_6.size() t_6 = self.l_35(t_6) t_8 = t_8[0] t_6 = t_6.view(t_8, (- 1), 32, 128) t_6 = t_6.transpose(1, 2) t_2 = t_2.view(t_8, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_3 = t_3.view(t_8, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_2 = t_2.transpose(3, 2) t_2 = torch.matmul(t_6, t_2) t_2 += x4 t_6 = t_2.float() t_6 = torch.nn.functional.softmax(t_6, dim=(- 1), _stacklevel=3, dtype=None) t_2 = t_6.type_as(t_2) t_2 = self.l_38(t_2) t_3 = torch.matmul(t_2, t_3) t_3 = t_3.transpose(1, 2) t_3 = t_3.contiguous() t_8 = t_3.view(t_8, (- 1), 4096) t_8 = self.l_39(t_8) t_8 = self.l_40(t_8) t_8 = (t_1 + t_8) t_1 = self.l_41(t_8) t_1 = self.l_42(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_43(t_1) t_1 = self.l_44(t_1) t_1 = self.l_45(t_1) t_1 = (t_8 + t_1) t_8 = self.l_46(t_1) t_3 = t_8.size() t_2 = self.l_47(t_8) t_6 = self.l_48(t_8) t_8 = self.l_49(t_8) t_3 = t_3[0] t_2 = t_2.view(t_3, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_6 = t_6.view(t_3, (- 1), 32, 128) t_6 = t_6.transpose(1, 2) t_8 = t_8.view(t_3, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_6 = t_6.transpose(3, 2) t_6 = torch.matmul(t_2, t_6) t_6 += x3 t_2 = t_6.float() t_2 = torch.nn.functional.softmax(t_2, dim=(- 1), _stacklevel=3, dtype=None) t_6 = t_2.type_as(t_6) t_6 = self.l_50(t_6) t_8 = torch.matmul(t_6, t_8) t_8 = t_8.transpose(1, 2) t_8 = t_8.contiguous() t_3 = t_8.view(t_3, (- 1), 4096) t_3 = self.l_51(t_3) t_3 = self.l_52(t_3) t_3 = (t_1 + t_3) t_1 = self.l_53(t_3) t_8 = t_1.size() t_1 = self.l_54(t_1) t_8 = t_8[0] t_1 = t_1.view(t_8, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_4 = t_4.view(t_8, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_5 = t_5.view(t_8, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_1, t_4) t_4 += x4 t_1 = t_4.float() t_1 = torch.nn.functional.softmax(t_1, dim=(- 1), _stacklevel=3, dtype=None) t_4 = t_1.type_as(t_4) t_4 = self.l_57(t_4) t_5 = torch.matmul(t_4, t_5) t_5 = t_5.transpose(1, 2) t_5 = t_5.contiguous() t_8 = t_5.view(t_8, (- 1), 4096) t_8 = self.l_58(t_8) t_8 = self.l_59(t_8) t_8 = (t_3 + t_8) return list(flatten((x0, x3, x4, t_8))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition26(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:26'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1] self.lookup = {'l_0': 'decoder.15.2.layer_norm', 'l_1': 'decoder.15.2.DenseReluDense.wi', 'l_2': 'decoder.15.2.DenseReluDense.dropout', 'l_3': 'decoder.15.2.DenseReluDense.wo', 'l_4': 'decoder.15.2.dropout', 'l_5': 'decoder.16.0.layer_norm', 'l_6': 'decoder.16.0.SelfAttention.q', 'l_7': 'decoder.16.0.SelfAttention.k', 'l_8': 'decoder.16.0.SelfAttention.v', 'l_9': 'decoder.16.0.SelfAttention.dropout', 'l_10': 'decoder.16.0.SelfAttention.o', 'l_11': 'decoder.16.0.dropout', 'l_12': 'decoder.16.1.layer_norm', 'l_13': 'decoder.16.1.EncDecAttention.q', 'l_14': 'decoder.16.1.EncDecAttention.k', 'l_15': 'decoder.16.1.EncDecAttention.v', 'l_16': 'decoder.16.1.EncDecAttention.dropout', 'l_17': 'decoder.16.1.EncDecAttention.o', 'l_18': 'decoder.16.1.dropout', 'l_19': 'decoder.16.2.layer_norm', 'l_20': 'decoder.16.2.DenseReluDense.wi', 'l_21': 'decoder.16.2.DenseReluDense.dropout', 'l_22': 'decoder.16.2.DenseReluDense.wo', 'l_23': 'decoder.16.2.dropout', 'l_24': 'decoder.17.0.layer_norm', 'l_25': 'decoder.17.0.SelfAttention.q', 'l_26': 'decoder.17.0.SelfAttention.k', 'l_27': 'decoder.17.0.SelfAttention.v', 'l_28': 'decoder.17.0.SelfAttention.dropout', 'l_29': 'decoder.17.0.SelfAttention.o', 'l_30': 'decoder.17.0.dropout', 'l_31': 'decoder.17.1.layer_norm', 'l_32': 'decoder.17.1.EncDecAttention.q', 'l_33': 'decoder.17.1.EncDecAttention.k', 'l_34': 'decoder.17.1.EncDecAttention.v', 'l_35': 'decoder.17.1.EncDecAttention.dropout', 'l_36': 'decoder.17.1.EncDecAttention.o', 'l_37': 'decoder.17.1.dropout', 'l_38': 'decoder.17.2.layer_norm', 'l_39': 'decoder.17.2.DenseReluDense.wi', 'l_40': 'decoder.17.2.DenseReluDense.dropout', 'l_41': 'decoder.17.2.DenseReluDense.wo', 'l_42': 'decoder.17.2.dropout', 'l_43': 'decoder.18.0.layer_norm', 'l_44': 'decoder.18.0.SelfAttention.q', 'l_45': 'decoder.18.0.SelfAttention.k', 'l_46': 'decoder.18.0.SelfAttention.v'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_14(x0) t_1 = self.l_15(x0) t_2 = self.l_33(x0) t_3 = self.l_34(x0) t_4 = self.l_0(x3) t_4 = self.l_1(t_4) t_4 = torch.nn.functional.relu(t_4, inplace=False) t_4 = self.l_2(t_4) t_4 = self.l_3(t_4) t_4 = self.l_4(t_4) t_4 = (x3 + t_4) t_5 = self.l_5(t_4) t_6 = t_5.size() t_7 = self.l_6(t_5) t_8 = self.l_7(t_5) t_5 = self.l_8(t_5) t_6 = t_6[0] t_7 = t_7.view(t_6, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_8 = t_8.view(t_6, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_5 = t_5.view(t_6, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_8 = t_8.transpose(3, 2) t_8 = torch.matmul(t_7, t_8) t_8 += x1 t_7 = t_8.float() t_7 = torch.nn.functional.softmax(t_7, dim=(- 1), _stacklevel=3, dtype=None) t_8 = t_7.type_as(t_8) t_8 = self.l_9(t_8) t_5 = torch.matmul(t_8, t_5) t_5 = t_5.transpose(1, 2) t_5 = t_5.contiguous() t_6 = t_5.view(t_6, (- 1), 4096) t_6 = self.l_10(t_6) t_6 = self.l_11(t_6) t_6 = (t_4 + t_6) t_4 = self.l_12(t_6) t_5 = t_4.size() t_4 = self.l_13(t_4) t_5 = t_5[0] t_4 = t_4.view(t_5, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_0 = t_0.view(t_5, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = t_1.view(t_5, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_0 = t_0.transpose(3, 2) t_0 = torch.matmul(t_4, t_0) t_0 += x2 t_4 = t_0.float() t_4 = torch.nn.functional.softmax(t_4, dim=(- 1), _stacklevel=3, dtype=None) t_0 = t_4.type_as(t_0) t_0 = self.l_16(t_0) t_1 = torch.matmul(t_0, t_1) t_1 = t_1.transpose(1, 2) t_1 = t_1.contiguous() t_5 = t_1.view(t_5, (- 1), 4096) t_5 = self.l_17(t_5) t_5 = self.l_18(t_5) t_5 = (t_6 + t_5) t_6 = self.l_19(t_5) t_6 = self.l_20(t_6) t_6 = torch.nn.functional.relu(t_6, inplace=False) t_6 = self.l_21(t_6) t_6 = self.l_22(t_6) t_6 = self.l_23(t_6) t_6 = (t_5 + t_6) t_5 = self.l_24(t_6) t_1 = t_5.size() t_0 = self.l_25(t_5) t_4 = self.l_26(t_5) t_5 = self.l_27(t_5) t_1 = t_1[0] t_0 = t_0.view(t_1, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_4 = t_4.view(t_1, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_5 = t_5.view(t_1, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_4 = t_4.transpose(3, 2) t_4 = torch.matmul(t_0, t_4) t_4 += x1 t_0 = t_4.float() t_0 = torch.nn.functional.softmax(t_0, dim=(- 1), _stacklevel=3, dtype=None) t_4 = t_0.type_as(t_4) t_4 = self.l_28(t_4) t_5 = torch.matmul(t_4, t_5) t_5 = t_5.transpose(1, 2) t_5 = t_5.contiguous() t_1 = t_5.view(t_1, (- 1), 4096) t_1 = self.l_29(t_1) t_1 = self.l_30(t_1) t_1 = (t_6 + t_1) t_6 = self.l_31(t_1) t_5 = t_6.size() t_6 = self.l_32(t_6) t_5 = t_5[0] t_6 = t_6.view(t_5, (- 1), 32, 128) t_6 = t_6.transpose(1, 2) t_2 = t_2.view(t_5, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_3 = t_3.view(t_5, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_2 = t_2.transpose(3, 2) t_2 = torch.matmul(t_6, t_2) t_2 += x2 t_6 = t_2.float() t_6 = torch.nn.functional.softmax(t_6, dim=(- 1), _stacklevel=3, dtype=None) t_2 = t_6.type_as(t_2) t_2 = self.l_35(t_2) t_3 = torch.matmul(t_2, t_3) t_3 = t_3.transpose(1, 2) t_3 = t_3.contiguous() t_5 = t_3.view(t_5, (- 1), 4096) t_5 = self.l_36(t_5) t_5 = self.l_37(t_5) t_5 = (t_1 + t_5) t_1 = self.l_38(t_5) t_1 = self.l_39(t_1) t_1 = torch.nn.functional.relu(t_1, inplace=False) t_1 = self.l_40(t_1) t_1 = self.l_41(t_1) t_1 = self.l_42(t_1) t_1 = (t_5 + t_1) t_5 = self.l_43(t_1) t_3 = self.l_44(t_5) t_2 = self.l_45(t_5) t_6 = self.l_46(t_5) return list(flatten((x0, x1, x2, t_1, t_5, t_3, t_2, t_6))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition27(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerSelfAttention[0]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerSelfAttention[0]/T5Attention[SelfAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerSelfAttention[0]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerCrossAttention[1]/T5LayerNorm[layer_norm]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:27'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.18.0.SelfAttention.dropout', 'l_1': 'decoder.18.0.SelfAttention.o', 'l_2': 'decoder.18.0.dropout', 'l_3': 'decoder.18.1.layer_norm', 'l_4': 'decoder.18.1.EncDecAttention.q', 'l_5': 'decoder.18.1.EncDecAttention.dropout', 'l_6': 'decoder.18.1.EncDecAttention.o', 'l_7': 'decoder.18.1.dropout', 'l_8': 'decoder.18.2.layer_norm', 'l_9': 'decoder.18.2.DenseReluDense.wi', 'l_10': 'decoder.18.2.DenseReluDense.dropout', 'l_11': 'decoder.18.2.DenseReluDense.wo', 'l_12': 'decoder.18.2.dropout', 'l_13': 'decoder.19.0.layer_norm', 'l_14': 'decoder.19.0.SelfAttention.q', 'l_15': 'decoder.19.0.SelfAttention.k', 'l_16': 'decoder.19.0.SelfAttention.v', 'l_17': 'decoder.19.0.SelfAttention.dropout', 'l_18': 'decoder.19.0.SelfAttention.o', 'l_19': 'decoder.19.0.dropout', 'l_20': 'decoder.19.1.layer_norm', 'l_21': 'decoder.19.1.EncDecAttention.q', 'l_22': 'decoder.19.1.EncDecAttention.v', 'l_23': 'decoder.19.1.EncDecAttention.dropout', 'l_24': 'decoder.19.1.EncDecAttention.o', 'l_25': 'decoder.19.1.dropout', 'l_26': 'decoder.19.2.layer_norm', 'l_27': 'decoder.19.2.DenseReluDense.wi', 'l_28': 'decoder.19.2.DenseReluDense.dropout', 'l_29': 'decoder.19.2.DenseReluDense.wo', 'l_30': 'decoder.19.2.dropout', 'l_31': 'decoder.20.0.layer_norm', 'l_32': 'decoder.20.0.SelfAttention.q', 'l_33': 'decoder.20.0.SelfAttention.k', 'l_34': 'decoder.20.0.SelfAttention.v', 'l_35': 'decoder.20.0.SelfAttention.dropout', 'l_36': 'decoder.20.0.SelfAttention.o', 'l_37': 'decoder.20.0.dropout', 'l_38': 'decoder.20.1.layer_norm', 'l_39': 'decoder.20.1.EncDecAttention.q', 'l_40': 'decoder.20.1.EncDecAttention.k', 'l_41': 'decoder.20.1.EncDecAttention.v', 'l_42': 'decoder.20.1.EncDecAttention.dropout', 'l_43': 'decoder.20.1.EncDecAttention.o', 'l_44': 'decoder.20.1.dropout', 'l_45': 'decoder.20.2.layer_norm', 'l_46': 'decoder.20.2.DenseReluDense.wi', 'l_47': 'decoder.20.2.DenseReluDense.dropout', 'l_48': 'decoder.20.2.DenseReluDense.wo', 'l_49': 'decoder.20.2.dropout', 'l_50': 'decoder.21.0.layer_norm', 'l_51': 'decoder.21.0.SelfAttention.q', 'l_52': 'decoder.21.0.SelfAttention.k', 'l_53': 'decoder.21.0.SelfAttention.v', 'l_54': 'decoder.21.0.SelfAttention.dropout', 'l_55': 'decoder.21.0.SelfAttention.o', 'l_56': 'decoder.21.0.dropout', 'l_57': 'decoder.21.1.layer_norm', 'l_58': 'decoder.21.1.EncDecAttention.q', 'l_59': 'decoder.21.1.EncDecAttention.k', 'l_60': 'decoder.21.1.EncDecAttention.v', 'l_61': 'decoder.21.1.EncDecAttention.dropout', 'l_62': 'decoder.21.1.EncDecAttention.o', 'l_63': 'decoder.21.1.dropout', 'l_64': 'decoder.21.2.layer_norm', 'l_65': 'decoder.21.2.DenseReluDense.wi', 'l_66': 'decoder.21.2.DenseReluDense.dropout', 'l_67': 'decoder.21.2.DenseReluDense.wo', 'l_68': 'decoder.21.2.dropout', 'l_69': 'decoder.22.0.layer_norm', 'l_70': 'decoder.22.0.SelfAttention.q', 'l_71': 'decoder.22.0.SelfAttention.k', 'l_72': 'decoder.22.0.SelfAttention.v', 'l_73': 'decoder.22.0.SelfAttention.dropout', 'l_74': 'decoder.22.0.SelfAttention.o', 'l_75': 'decoder.22.0.dropout', 'l_76': 'decoder.22.1.layer_norm', 'l_77': 'decoder.22.1.EncDecAttention.q', 'l_78': 'decoder.22.1.EncDecAttention.k', 'l_79': 'decoder.22.1.EncDecAttention.v', 'l_80': 'decoder.22.1.EncDecAttention.dropout', 'l_81': 'decoder.22.1.EncDecAttention.o', 'l_82': 'decoder.22.1.dropout', 'l_83': 'decoder.22.2.layer_norm', 'l_84': 'decoder.22.2.DenseReluDense.wi', 'l_85': 'decoder.22.2.DenseReluDense.dropout', 'l_86': 'decoder.22.2.DenseReluDense.wo', 'l_87': 'decoder.22.2.dropout', 'l_88': 'decoder.23.0.layer_norm', 'l_89': 'decoder.23.0.SelfAttention.q', 'l_90': 'decoder.23.0.SelfAttention.k', 'l_91': 'decoder.23.0.SelfAttention.v', 'l_92': 'decoder.23.0.SelfAttention.dropout', 'l_93': 'decoder.23.0.SelfAttention.o', 'l_94': 'decoder.23.0.dropout', 'l_95': 'decoder.23.1.layer_norm'} self.to(self.device) def forward(self, *args): (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) = unflatten(args, self.input_structure) t_0 = self.l_22(x0) t_1 = self.l_40(x0) t_2 = self.l_41(x0) t_3 = self.l_59(x0) t_4 = self.l_60(x0) t_5 = self.l_78(x0) t_6 = self.l_79(x0) t_7 = x7.size() t_7 = t_7[0] t_8 = x8.view(t_7, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_9 = x9.view(t_7, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_10 = x10.view(t_7, (- 1), 32, 128) t_10 = t_10.transpose(1, 2) t_9 = t_9.transpose(3, 2) t_9 = torch.matmul(t_8, t_9) t_9 += x4 t_8 = t_9.float() t_8 = torch.nn.functional.softmax(t_8, dim=(- 1), _stacklevel=3, dtype=None) t_9 = t_8.type_as(t_9) t_9 = self.l_0(t_9) t_10 = torch.matmul(t_9, t_10) t_10 = t_10.transpose(1, 2) t_10 = t_10.contiguous() t_7 = t_10.view(t_7, (- 1), 4096) t_7 = self.l_1(t_7) t_7 = self.l_2(t_7) t_7 = (x6 + t_7) t_10 = self.l_3(t_7) t_9 = t_10.size() t_10 = self.l_4(t_10) t_9 = t_9[0] t_10 = t_10.view(t_9, (- 1), 32, 128) t_10 = t_10.transpose(1, 2) t_8 = x1.view(t_9, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_11 = x2.view(t_9, (- 1), 32, 128) t_11 = t_11.transpose(1, 2) t_8 = t_8.transpose(3, 2) t_8 = torch.matmul(t_10, t_8) t_8 += x5 t_10 = t_8.float() t_10 = torch.nn.functional.softmax(t_10, dim=(- 1), _stacklevel=3, dtype=None) t_8 = t_10.type_as(t_8) t_8 = self.l_5(t_8) t_11 = torch.matmul(t_8, t_11) t_11 = t_11.transpose(1, 2) t_11 = t_11.contiguous() t_9 = t_11.view(t_9, (- 1), 4096) t_9 = self.l_6(t_9) t_9 = self.l_7(t_9) t_9 = (t_7 + t_9) t_7 = self.l_8(t_9) t_7 = self.l_9(t_7) t_7 = torch.nn.functional.relu(t_7, inplace=False) t_7 = self.l_10(t_7) t_7 = self.l_11(t_7) t_7 = self.l_12(t_7) t_7 = (t_9 + t_7) t_9 = self.l_13(t_7) t_11 = t_9.size() t_8 = self.l_14(t_9) t_10 = self.l_15(t_9) t_9 = self.l_16(t_9) t_11 = t_11[0] t_8 = t_8.view(t_11, (- 1), 32, 128) t_8 = t_8.transpose(1, 2) t_10 = t_10.view(t_11, (- 1), 32, 128) t_10 = t_10.transpose(1, 2) t_9 = t_9.view(t_11, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_10 = t_10.transpose(3, 2) t_10 = torch.matmul(t_8, t_10) t_10 += x4 t_8 = t_10.float() t_8 = torch.nn.functional.softmax(t_8, dim=(- 1), _stacklevel=3, dtype=None) t_10 = t_8.type_as(t_10) t_10 = self.l_17(t_10) t_9 = torch.matmul(t_10, t_9) t_9 = t_9.transpose(1, 2) t_9 = t_9.contiguous() t_11 = t_9.view(t_11, (- 1), 4096) t_11 = self.l_18(t_11) t_11 = self.l_19(t_11) t_11 = (t_7 + t_11) t_7 = self.l_20(t_11) t_9 = t_7.size() t_7 = self.l_21(t_7) t_9 = t_9[0] t_7 = t_7.view(t_9, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_10 = x3.view(t_9, (- 1), 32, 128) t_10 = t_10.transpose(1, 2) t_0 = t_0.view(t_9, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_10 = t_10.transpose(3, 2) t_10 = torch.matmul(t_7, t_10) t_10 += x5 t_7 = t_10.float() t_7 = torch.nn.functional.softmax(t_7, dim=(- 1), _stacklevel=3, dtype=None) t_10 = t_7.type_as(t_10) t_10 = self.l_23(t_10) t_0 = torch.matmul(t_10, t_0) t_0 = t_0.transpose(1, 2) t_0 = t_0.contiguous() t_9 = t_0.view(t_9, (- 1), 4096) t_9 = self.l_24(t_9) t_9 = self.l_25(t_9) t_9 = (t_11 + t_9) t_11 = self.l_26(t_9) t_11 = self.l_27(t_11) t_11 = torch.nn.functional.relu(t_11, inplace=False) t_11 = self.l_28(t_11) t_11 = self.l_29(t_11) t_11 = self.l_30(t_11) t_11 = (t_9 + t_11) t_9 = self.l_31(t_11) t_0 = t_9.size() t_10 = self.l_32(t_9) t_7 = self.l_33(t_9) t_9 = self.l_34(t_9) t_0 = t_0[0] t_10 = t_10.view(t_0, (- 1), 32, 128) t_10 = t_10.transpose(1, 2) t_7 = t_7.view(t_0, (- 1), 32, 128) t_7 = t_7.transpose(1, 2) t_9 = t_9.view(t_0, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_7 = t_7.transpose(3, 2) t_7 = torch.matmul(t_10, t_7) t_7 += x4 t_10 = t_7.float() t_10 = torch.nn.functional.softmax(t_10, dim=(- 1), _stacklevel=3, dtype=None) t_7 = t_10.type_as(t_7) t_7 = self.l_35(t_7) t_9 = torch.matmul(t_7, t_9) t_9 = t_9.transpose(1, 2) t_9 = t_9.contiguous() t_0 = t_9.view(t_0, (- 1), 4096) t_0 = self.l_36(t_0) t_0 = self.l_37(t_0) t_0 = (t_11 + t_0) t_11 = self.l_38(t_0) t_9 = t_11.size() t_11 = self.l_39(t_11) t_9 = t_9[0] t_11 = t_11.view(t_9, (- 1), 32, 128) t_11 = t_11.transpose(1, 2) t_1 = t_1.view(t_9, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_2 = t_2.view(t_9, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_1 = t_1.transpose(3, 2) t_1 = torch.matmul(t_11, t_1) t_1 += x5 t_11 = t_1.float() t_11 = torch.nn.functional.softmax(t_11, dim=(- 1), _stacklevel=3, dtype=None) t_1 = t_11.type_as(t_1) t_1 = self.l_42(t_1) t_2 = torch.matmul(t_1, t_2) t_2 = t_2.transpose(1, 2) t_2 = t_2.contiguous() t_9 = t_2.view(t_9, (- 1), 4096) t_9 = self.l_43(t_9) t_9 = self.l_44(t_9) t_9 = (t_0 + t_9) t_0 = self.l_45(t_9) t_0 = self.l_46(t_0) t_0 = torch.nn.functional.relu(t_0, inplace=False) t_0 = self.l_47(t_0) t_0 = self.l_48(t_0) t_0 = self.l_49(t_0) t_0 = (t_9 + t_0) t_9 = self.l_50(t_0) t_2 = t_9.size() t_1 = self.l_51(t_9) t_11 = self.l_52(t_9) t_9 = self.l_53(t_9) t_2 = t_2[0] t_1 = t_1.view(t_2, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_11 = t_11.view(t_2, (- 1), 32, 128) t_11 = t_11.transpose(1, 2) t_9 = t_9.view(t_2, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_11 = t_11.transpose(3, 2) t_11 = torch.matmul(t_1, t_11) t_11 += x4 t_1 = t_11.float() t_1 = torch.nn.functional.softmax(t_1, dim=(- 1), _stacklevel=3, dtype=None) t_11 = t_1.type_as(t_11) t_11 = self.l_54(t_11) t_9 = torch.matmul(t_11, t_9) t_9 = t_9.transpose(1, 2) t_9 = t_9.contiguous() t_2 = t_9.view(t_2, (- 1), 4096) t_2 = self.l_55(t_2) t_2 = self.l_56(t_2) t_2 = (t_0 + t_2) t_0 = self.l_57(t_2) t_9 = t_0.size() t_0 = self.l_58(t_0) t_9 = t_9[0] t_0 = t_0.view(t_9, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_3 = t_3.view(t_9, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_4 = t_4.view(t_9, (- 1), 32, 128) t_4 = t_4.transpose(1, 2) t_3 = t_3.transpose(3, 2) t_3 = torch.matmul(t_0, t_3) t_3 += x5 t_0 = t_3.float() t_0 = torch.nn.functional.softmax(t_0, dim=(- 1), _stacklevel=3, dtype=None) t_3 = t_0.type_as(t_3) t_3 = self.l_61(t_3) t_4 = torch.matmul(t_3, t_4) t_4 = t_4.transpose(1, 2) t_4 = t_4.contiguous() t_9 = t_4.view(t_9, (- 1), 4096) t_9 = self.l_62(t_9) t_9 = self.l_63(t_9) t_9 = (t_2 + t_9) t_2 = self.l_64(t_9) t_2 = self.l_65(t_2) t_2 = torch.nn.functional.relu(t_2, inplace=False) t_2 = self.l_66(t_2) t_2 = self.l_67(t_2) t_2 = self.l_68(t_2) t_2 = (t_9 + t_2) t_9 = self.l_69(t_2) t_4 = t_9.size() t_3 = self.l_70(t_9) t_0 = self.l_71(t_9) t_9 = self.l_72(t_9) t_4 = t_4[0] t_3 = t_3.view(t_4, (- 1), 32, 128) t_3 = t_3.transpose(1, 2) t_0 = t_0.view(t_4, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_9 = t_9.view(t_4, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_0 = t_0.transpose(3, 2) t_0 = torch.matmul(t_3, t_0) t_0 += x4 t_3 = t_0.float() t_3 = torch.nn.functional.softmax(t_3, dim=(- 1), _stacklevel=3, dtype=None) t_0 = t_3.type_as(t_0) t_0 = self.l_73(t_0) t_9 = torch.matmul(t_0, t_9) t_9 = t_9.transpose(1, 2) t_9 = t_9.contiguous() t_4 = t_9.view(t_4, (- 1), 4096) t_4 = self.l_74(t_4) t_4 = self.l_75(t_4) t_4 = (t_2 + t_4) t_2 = self.l_76(t_4) t_9 = t_2.size() t_2 = self.l_77(t_2) t_9 = t_9[0] t_2 = t_2.view(t_9, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_5 = t_5.view(t_9, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_6 = t_6.view(t_9, (- 1), 32, 128) t_6 = t_6.transpose(1, 2) t_5 = t_5.transpose(3, 2) t_5 = torch.matmul(t_2, t_5) t_5 += x5 t_2 = t_5.float() t_2 = torch.nn.functional.softmax(t_2, dim=(- 1), _stacklevel=3, dtype=None) t_5 = t_2.type_as(t_5) t_5 = self.l_80(t_5) t_6 = torch.matmul(t_5, t_6) t_6 = t_6.transpose(1, 2) t_6 = t_6.contiguous() t_9 = t_6.view(t_9, (- 1), 4096) t_9 = self.l_81(t_9) t_9 = self.l_82(t_9) t_9 = (t_4 + t_9) t_4 = self.l_83(t_9) t_4 = self.l_84(t_4) t_4 = torch.nn.functional.relu(t_4, inplace=False) t_4 = self.l_85(t_4) t_4 = self.l_86(t_4) t_4 = self.l_87(t_4) t_4 = (t_9 + t_4) t_9 = self.l_88(t_4) t_6 = t_9.size() t_5 = self.l_89(t_9) t_2 = self.l_90(t_9) t_9 = self.l_91(t_9) t_6 = t_6[0] t_5 = t_5.view(t_6, (- 1), 32, 128) t_5 = t_5.transpose(1, 2) t_2 = t_2.view(t_6, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_9 = t_9.view(t_6, (- 1), 32, 128) t_9 = t_9.transpose(1, 2) t_2 = t_2.transpose(3, 2) t_2 = torch.matmul(t_5, t_2) t_2 += x4 t_5 = t_2.float() t_5 = torch.nn.functional.softmax(t_5, dim=(- 1), _stacklevel=3, dtype=None) t_2 = t_5.type_as(t_2) t_2 = self.l_92(t_2) t_9 = torch.matmul(t_2, t_9) t_9 = t_9.transpose(1, 2) t_9 = t_9.contiguous() t_6 = t_9.view(t_6, (- 1), 4096) t_6 = self.l_93(t_6) t_6 = self.l_94(t_6) t_6 = (t_4 + t_6) t_4 = self.l_95(t_6) t_9 = t_4.size() t_9 = t_9[0] return list(flatten((x0, x5, t_6, t_4, t_9))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition28(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[q]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[k]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[v]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerCrossAttention[1]/T5Attention[EncDecAttention]/Linear[o]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerCrossAttention[1]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerFF[2]/T5LayerNorm[layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wi]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerFF[2]/T5DenseReluDense[DenseReluDense]/Linear[wo]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]/T5LayerFF[2]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5LayerNorm[final_layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/Dropout[dropout]', 'T5ForConditionalGeneration/Linear[lm_head]', 'T5ForConditionalGeneration/CrossEntropyLoss[lm_loss]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:28'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.23.1.EncDecAttention.q', 'l_1': 'decoder.23.1.EncDecAttention.k', 'l_2': 'decoder.23.1.EncDecAttention.v', 'l_3': 'decoder.23.1.EncDecAttention.dropout', 'l_4': 'decoder.23.1.EncDecAttention.o', 'l_5': 'decoder.23.1.dropout', 'l_6': 'decoder.23.2.layer_norm', 'l_7': 'decoder.23.2.DenseReluDense.wi', 'l_8': 'decoder.23.2.DenseReluDense.dropout', 'l_9': 'decoder.23.2.DenseReluDense.wo', 'l_10': 'decoder.23.2.dropout', 'l_11': 'decoder.final_layer_norm', 'l_12': 'decoder.dropout', 'l_13': 'lm_head', 'l_14': 'lm_loss'} self.to(self.device) def forward(self, *args): (lm_labels, x0, x1, x2, x3, x4) = unflatten(args, self.input_structure) t_0 = self.l_1(x0) t_1 = self.l_2(x0) t_2 = self.l_0(x3) t_2 = t_2.view(x4, (- 1), 32, 128) t_2 = t_2.transpose(1, 2) t_0 = t_0.view(x4, (- 1), 32, 128) t_0 = t_0.transpose(1, 2) t_1 = t_1.view(x4, (- 1), 32, 128) t_1 = t_1.transpose(1, 2) t_0 = t_0.transpose(3, 2) t_0 = torch.matmul(t_2, t_0) t_0 += x1 t_2 = t_0.float() t_2 = torch.nn.functional.softmax(t_2, dim=(- 1), _stacklevel=3, dtype=None) t_0 = t_2.type_as(t_0) t_0 = self.l_3(t_0) t_1 = torch.matmul(t_0, t_1) t_1 = t_1.transpose(1, 2) t_1 = t_1.contiguous() t_1 = t_1.view(x4, (- 1), 4096) t_1 = self.l_4(t_1) t_1 = self.l_5(t_1) t_1 = (x2 + t_1) t_0 = self.l_6(t_1) t_0 = self.l_7(t_0) t_0 = torch.nn.functional.relu(t_0, inplace=False) t_0 = self.l_8(t_0) t_0 = self.l_9(t_0) t_0 = self.l_10(t_0) t_0 = (t_1 + t_0) t_0 = self.l_11(t_0) t_0 = self.l_12(t_0) t_0 = (t_0 * 0.03125) t_0 = self.l_13(t_0) t_1 = t_0.size((- 1)) t_1 = t_0.view((- 1), t_1) t_0 = lm_labels.view((- 1)) t_0 = self.l_14(t_1, t_0) return (t_0,) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
def traverse_model(module: nn.Module, depth: int, prefix: Optional[str]=None, basic_blocks: Tuple[Type[nn.Module]]=(), full: bool=False) -> Iterator[Tuple[(nn.Module, str, nn.Module, Optional[bool])]]: '\n iterate over model layers yielding the layer,layer_scope,encasing_module\n Parameters:\n -----------\n model:\n the model to iterate over\n depth:\n how far down in the model tree to go\n basic_blocks:\n a list of modules that if encountered will not be broken down\n full:\n whether to yield only layers specified by the depth and basic_block options or to yield all layers\n ' if (prefix is None): prefix = type(module).__name__ for (name, sub_module) in module.named_children(): scope = (((prefix + '/') + type(sub_module).__name__) + f'[{name}]') if ((len(list(sub_module.children())) == 0) or isinstance(sub_module, tuple(basic_blocks)) or (depth == 0)): if full: (yield (sub_module, scope, module, True)) else: (yield (sub_module, scope, module)) else: if full: (yield (sub_module, scope, module, False)) (yield from traverse_model(sub_module, (depth - 1), scope, basic_blocks, full))
def layerDict(model: nn.Module, depth=1000, basic_blocks=()) -> Dict[(str, nn.Module)]: return {s: l for (l, s, _) in traverse_model(model, depth, basic_blocks=basic_blocks)}
def traverse_params_buffs(module: nn.Module, prefix: Optional[str]=None) -> Iterator[Tuple[(torch.tensor, str)]]: "\n iterate over model's buffers and parameters yielding obj,obj_scope\n\n Parameters:\n -----------\n model:\n the model to iterate over\n " if (prefix is None): prefix = type(module).__name__ for (param_name, param) in module.named_parameters(recurse=False): param_scope = f'{prefix}/{type(param).__name__}[{param_name}]' (yield (param, param_scope)) for (buffer_name, buffer) in module.named_buffers(recurse=False): buffer_scope = f'{prefix}/{type(buffer).__name__}[{buffer_name}]' (yield (buffer, buffer_scope)) for (name, sub_module) in module.named_children(): (yield from traverse_params_buffs(sub_module, (((prefix + '/') + type(sub_module).__name__) + f'[{name}]')))
def tensorDict(model: nn.Module) -> OrderedDict[(str, Tensor)]: return collections.OrderedDict(((s, t) for (t, s) in traverse_params_buffs(model)))
def move_tensors(ts, device): def move(t): if isinstance(t, (nn.Module, Tensor)): return t.to(device) return t return nested_map(move, ts)
def nested_map(func, ts, full=False): if isinstance(ts, torch.Size): return func(ts) elif isinstance(ts, (list, tuple, set)): return type(ts)((nested_map(func, t, full=full) for t in ts)) elif isinstance(ts, dict): return {k: nested_map(func, v, full=full) for (k, v) in ts.items()} elif (isinstance(ts, slice) and full): start = nested_map(func, ts.start, full=full) stop = nested_map(func, ts.stop, full=full) step = nested_map(func, ts.step, full=full) return slice(start, stop, step) return func(ts)
def flatten(ts): if isinstance(ts, torch.Size): (yield ts) elif isinstance(ts, (list, tuple, set)): (yield from chain(*[flatten(t) for t in ts])) elif isinstance(ts, dict): (yield from chain(*[flatten(t) for (k, t) in sorted(ts.items(), key=(lambda t: t[0]))])) else: (yield ts)
def unflatten(xs, structure): return _unflatten(xs, structure)[0]
def _unflatten(xs, structure): if isinstance(structure, torch.Size): return (xs[0], 1) if (not isinstance(structure, (list, tuple, set, dict))): return (xs[0], 1) if isinstance(structure, (list, tuple, set)): offset = 0 elements = [] for s in structure: (e, n) = _unflatten(xs[offset:], s) elements.append(e) offset += n return (type(structure)(elements), offset) assert isinstance(structure, dict) offset = 0 elements = dict() for (k, v) in sorted(structure.items(), key=(lambda t: t[0])): (e, n) = _unflatten(xs[offset:], v) elements[k] = e offset += n return (elements, offset)
def state_dict(partition, *args, **kwargs): state = nn.Module.state_dict(partition, *args, **kwargs) lookup = partition.lookup result = dict() for (k, v) in state.items(): if (k in lookup): result[lookup[k]] = v else: assert ('.' in k) split_idx = k.find('.') new_k = (lookup[k[:split_idx]] + k[split_idx:]) result[new_k] = v return result
def load_state_dict(partition, state_dict, strict=True): reverse_lookup = {v: k for (k, v) in partition.lookup.items()} device = partition.device keys = list(partition.state_dict(None).keys()) new_state = dict() for k in keys: if (k in reverse_lookup): new_state[reverse_lookup[k]] = state_dict[k].to(device) continue idx = k.rfind('.') to_replace = k[:idx] if (to_replace in reverse_lookup): key = (reverse_lookup[to_replace] + k[idx:]) new_state[key] = state_dict[k].to(device) nn.Module.load_state_dict(partition, new_state, strict=strict)
def named_buffers(partition, prefix='', recurse=True): params = nn.Module.named_buffers(partition, prefix=prefix, recurse=recurse) lookup = partition.lookup for (k, v) in params: if (k in lookup): (yield (lookup[k], v)) else: assert ('.' in k) split_idx = k.find('.') new_k = (lookup[k[:split_idx]] + k[split_idx:]) (yield (new_k, v))
def named_parameters(partition, prefix='', recurse=True): params = nn.Module.named_parameters(partition, prefix=prefix, recurse=recurse) lookup = partition.lookup for (k, v) in params: if (k in lookup): (yield (lookup[k], v)) else: assert ('.' in k) split_idx = k.find('.') new_k = (lookup[k[:split_idx]] + k[split_idx:]) (yield (new_k, v))
def cpu(partition): partition.device = torch.device('cpu') return nn.Module.cpu(partition)
def cuda(partition, device=None): if (device is None): device = torch.cuda.current_device() partition.device = torch.device(device) return nn.Module.cuda(partition, partition.device)
def to(partition, *args, **kwargs): device = None if ('device' in kwargs): device = kwargs['device'] elif ('tensor' in kwargs): device = kwargs['tensor'].device if args: if isinstance(args[0], (torch.device, int, str)): device = args[0] if torch.is_tensor(args[0]): device = args[0].device if (not (device is None)): partition.device = torch.device(device) return nn.Module.to(partition, *args, **kwargs)
def create_pipeline_configuration(DEBUG=False, batch_size=4): config = {'batch_dim': 0, 'depth': 10000, 'basic_blocks': (CrossEntropyLoss, StatelessEmbedding, T5Block, Linear, T5LayerNorm, Dropout), 'model_inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'is_batched': True, 'used_by': [0, 1, 2, 3]}, 'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'is_batched': True, 'used_by': [3, 4, 5, 6, 7]}, 'decoder_input_ids': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'is_batched': True, 'used_by': [0]}, 'input_ids': {'shape': torch.Size([4, 512]), 'dtype': torch.int64, 'is_batched': True, 'used_by': [0]}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'is_batched': True, 'used_by': [3, 4, 5, 6, 7]}, 'lm_labels': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'is_batched': True, 'used_by': [7]}}, 'model_outputs': {'T5ForConditionalGeneration/CrossEntropyLoss[lm_loss]': {'shape': torch.Size([1]), 'dtype': torch.float32, 'is_batched': False, 'created_by': 7}}, 'stages': {0: {'stage_cls': Partition0, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'decoder_input_ids': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'input_ids': {'shape': torch.Size([4, 512]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_1': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [1]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[6]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [1]}, 'T5ForConditionalGeneration/T5Stack[decoder]/StatelessEmbedding[embed_tokens]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [1]}}, 'devices': [('cpu' if DEBUG else 'cuda:0')], 'stage_depth': 7}, 1: {'stage_cls': Partition1, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_1': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 0}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[6]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 0}, 'T5ForConditionalGeneration/T5Stack[decoder]/StatelessEmbedding[embed_tokens]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 0}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_2': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [2]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [2]}, 'T5ForConditionalGeneration/T5Stack[decoder]/Dropout[dropout]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [3]}}, 'devices': [('cpu' if DEBUG else 'cuda:1')], 'stage_depth': 6}, 2: {'stage_cls': Partition2, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_2': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 1}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 1}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_3': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [3]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [3]}}, 'devices': [('cpu' if DEBUG else 'cuda:2')], 'stage_depth': 5}, 3: {'stage_cls': Partition3, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_3': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 2}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 2}, 'T5ForConditionalGeneration/T5Stack[decoder]/Dropout[dropout]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 1}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_4': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [4]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_4': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [4]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_4': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [4]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [4]}}, 'devices': [('cpu' if DEBUG else 'cuda:3')], 'stage_depth': 4}, 4: {'stage_cls': Partition4, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_4': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 3}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_4': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 3}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_4': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 3}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 3}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_5': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [5]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_5': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [5]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_5': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [5]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [5]}}, 'devices': [('cpu' if DEBUG else 'cuda:4')], 'stage_depth': 3}, 5: {'stage_cls': Partition5, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_5': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 4}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_5': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 4}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_5': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 4}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 4}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_6': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_6': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_6': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}}, 'devices': [('cpu' if DEBUG else 'cuda:5')], 'stage_depth': 2}, 6: {'stage_cls': Partition6, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_6': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_6': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_6': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_7': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_7': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_7': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}}, 'devices': [('cpu' if DEBUG else 'cuda:6')], 'stage_depth': 1}, 7: {'stage_cls': Partition7, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'lm_labels': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_7': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_7': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_7': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}}, 'outputs': {'T5ForConditionalGeneration/CrossEntropyLoss[lm_loss]': {'shape': torch.Size([1]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': False, 'used_by': [(- 1)]}}, 'devices': [('cpu' if DEBUG else 'cuda:7')], 'stage_depth': 0}}} batch_dim = config['batch_dim'] for d in chain(config['model_inputs'].values(), config['model_outputs'].values()): if d['is_batched']: shape = d['shape'] d['shape'] = torch.Size(((shape[:batch_dim] + (batch_size,)) + shape[(batch_dim + 1):])) for s in config['stages'].values(): for d in chain(s['inputs'].values(), s['outputs'].values()): if d['is_batched']: shape = d['shape'] d['shape'] = torch.Size(((shape[:batch_dim] + (batch_size,)) + shape[(batch_dim + 1):])) return config
class Partition0(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/StatelessEmbedding[embed_tokens]', 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[0]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[1]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[2]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[3]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[4]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[5]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[6]', 'T5ForConditionalGeneration/T5Stack[decoder]/StatelessEmbedding[embed_tokens]'] TENSORS = ['T5ForConditionalGeneration/Parameter[shared_embed_weight]'] def __init__(self, layers, tensors, device='cuda:0'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.embed_tokens', 'l_1': 'encoder.dropout', 'l_2': 'encoder.0', 'l_3': 'encoder.1', 'l_4': 'encoder.2', 'l_5': 'encoder.3', 'l_6': 'encoder.4', 'l_7': 'encoder.5', 'l_8': 'encoder.6', 'l_9': 'decoder.embed_tokens', 'p_0': 'shared_embed_weight'} self.to(self.device) def forward(self, *args): (attention_mask, decoder_input_ids, input_ids) = unflatten(args, self.input_structure) t_0 = input_ids.size() t_0 = t_0[(- 1)] t_0 = input_ids.view((- 1), t_0) t_0 = self.l_0(self.p_0, t_0) t_0 = self.l_1(t_0) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=None, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_1 = t_0[0] t_0 = t_0[1] t_1 = self.l_3(t_1, attention_mask=attention_mask, position_bias=t_0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_1 = self.l_4(t_1, attention_mask=attention_mask, position_bias=t_0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_1 = self.l_5(t_1, attention_mask=attention_mask, position_bias=t_0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_1 = self.l_6(t_1, attention_mask=attention_mask, position_bias=t_0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_1 = self.l_7(t_1, attention_mask=attention_mask, position_bias=t_0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_1 = self.l_8(t_1, attention_mask=attention_mask, position_bias=t_0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_2 = decoder_input_ids.size() t_2 = t_2[(- 1)] t_2 = decoder_input_ids.view((- 1), t_2) t_2 = self.l_9(self.p_0, t_2) return list(flatten((t_0, t_1, t_2))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition1(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[7]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[8]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[9]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[10]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[11]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]', 'T5ForConditionalGeneration/T5Stack[decoder]/Dropout[dropout]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:1'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1] self.lookup = {'l_0': 'encoder.7', 'l_1': 'encoder.8', 'l_2': 'encoder.9', 'l_3': 'encoder.10', 'l_4': 'encoder.11', 'l_5': 'encoder.12', 'l_6': 'encoder.13', 'l_7': 'decoder.dropout'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1, x2) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_3(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_4(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_5(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_6(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_1 = self.l_7(x2) return list(flatten((x0, t_0, t_1))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition2(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:2'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.14', 'l_1': 'encoder.15', 'l_2': 'encoder.16', 'l_3': 'encoder.17', 'l_4': 'encoder.18', 'l_5': 'encoder.19', 'l_6': 'encoder.20'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_3(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_4(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_5(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_6(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition3(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5LayerNorm[final_layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:3'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'encoder.21', 'l_1': 'encoder.22', 'l_2': 'encoder.23', 'l_3': 'encoder.final_layer_norm', 'l_4': 'encoder.dropout', 'l_5': 'decoder.0', 'l_6': 'decoder.1', 'l_7': 'decoder.2', 'l_8': 'decoder.3'} self.to(self.device) def forward(self, *args): (attention_mask, decoder_attention_mask, inverted_encoder_attention_mask, x0, x1, x2) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_3(t_0) t_0 = self.l_4(t_0) t_1 = self.l_5(x2, attention_mask=decoder_attention_mask, position_bias=None, encoder_hidden_states=t_0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=None) t_2 = t_1[0] t_3 = t_1[1] t_1 = t_1[2] t_2 = self.l_6(t_2, attention_mask=decoder_attention_mask, position_bias=t_3, encoder_hidden_states=t_0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=t_1) t_2 = self.l_7(t_2, attention_mask=decoder_attention_mask, position_bias=t_3, encoder_hidden_states=t_0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=t_1) t_2 = self.l_8(t_2, attention_mask=decoder_attention_mask, position_bias=t_3, encoder_hidden_states=t_0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=t_1) return list(flatten((t_0, t_3, t_1, t_2))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition4(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:4'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.4', 'l_1': 'decoder.5', 'l_2': 'decoder.6', 'l_3': 'decoder.7', 'l_4': 'decoder.8'} self.to(self.device) def forward(self, *args): (decoder_attention_mask, inverted_encoder_attention_mask, x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x3, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_1(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_2(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_3(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_4(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) return list(flatten((x0, x1, x2, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition5(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:5'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.9', 'l_1': 'decoder.10', 'l_2': 'decoder.11', 'l_3': 'decoder.12', 'l_4': 'decoder.13'} self.to(self.device) def forward(self, *args): (decoder_attention_mask, inverted_encoder_attention_mask, x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x3, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_1(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_2(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_3(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_4(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) return list(flatten((x0, x1, x2, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition6(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:6'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.14', 'l_1': 'decoder.15', 'l_2': 'decoder.16', 'l_3': 'decoder.17', 'l_4': 'decoder.18'} self.to(self.device) def forward(self, *args): (decoder_attention_mask, inverted_encoder_attention_mask, x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x3, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_1(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_2(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_3(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_4(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) return list(flatten((x0, x1, x2, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition7(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5LayerNorm[final_layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/Dropout[dropout]', 'T5ForConditionalGeneration/Linear[lm_head]', 'T5ForConditionalGeneration/CrossEntropyLoss[lm_loss]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:7'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.19', 'l_1': 'decoder.20', 'l_2': 'decoder.21', 'l_3': 'decoder.22', 'l_4': 'decoder.23', 'l_5': 'decoder.final_layer_norm', 'l_6': 'decoder.dropout', 'l_7': 'lm_head', 'l_8': 'lm_loss'} self.to(self.device) def forward(self, *args): (decoder_attention_mask, inverted_encoder_attention_mask, lm_labels, x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x3, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_1(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_2(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_3(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_4(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_5(t_0) t_0 = self.l_6(t_0) t_0 = (t_0 * 0.03125) t_0 = self.l_7(t_0) t_1 = t_0.size((- 1)) t_1 = t_0.view((- 1), t_1) t_0 = lm_labels.view((- 1)) t_0 = self.l_8(t_1, t_0) return (t_0,) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
def traverse_model(module: nn.Module, depth: int, prefix: Optional[str]=None, basic_blocks: Tuple[nn.Module]=(), full: bool=False) -> Iterator[Tuple[(nn.Module, str, nn.Module)]]: '\n iterate over model layers yielding the layer,layer_scope,encasing_module\n Parameters:\n -----------\n model:\n the model to iterate over\n depth:\n how far down in the model tree to go\n basic_blocks:\n a list of modules that if encountered will not be broken down\n full:\n whether to yield only layers specified by the depth and basick_block options or to yield all layers\n ' if (prefix is None): prefix = type(module).__name__ for (name, sub_module) in module.named_children(): scope = (((prefix + '/') + type(sub_module).__name__) + f'[{name}]') if ((len(list(sub_module.children())) == 0) or isinstance(sub_module, tuple(basic_blocks)) or (depth == 0)): if full: (yield (sub_module, scope, module, True)) else: (yield (sub_module, scope, module)) else: if full: (yield (sub_module, scope, module, False)) (yield from traverse_model(sub_module, (depth - 1), scope, basic_blocks, full))
def layerDict(model: nn.Module, depth=1000, basic_blocks=()) -> Dict[(str, nn.Module)]: return {s: l for (l, s, _) in traverse_model(model, depth, basic_blocks=basic_blocks)}
def traverse_params_buffs(module: nn.Module, prefix: Optional[str]=None) -> Iterator[Tuple[(torch.tensor, str)]]: "\n iterate over model's buffers and parameters yielding obj,obj_scope\n\n Parameters:\n -----------\n model:\n the model to iterate over\n " if (prefix is None): prefix = type(module).__name__ for (param_name, param) in module.named_parameters(recurse=False): param_scope = f'{prefix}/{type(param).__name__}[{param_name}]' (yield (param, param_scope)) for (buffer_name, buffer) in module.named_buffers(recurse=False): buffer_scope = f'{prefix}/{type(buffer).__name__}[{buffer_name}]' (yield (buffer, buffer_scope)) for (name, sub_module) in module.named_children(): (yield from traverse_params_buffs(sub_module, (((prefix + '/') + type(sub_module).__name__) + f'[{name}]')))
def tensorDict(model: nn.Module) -> OrderedDict[(str, Tensor)]: return collections.OrderedDict(((s, t) for (t, s) in traverse_params_buffs(model)))
def move_tensors(ts, device): def move(t): if isinstance(t, (nn.Module, Tensor)): return t.to(device) return t return nested_map(move, ts)
def nested_map(func, ts, full=False): if isinstance(ts, torch.Size): return func(ts) elif isinstance(ts, (list, tuple, set)): return type(ts)((nested_map(func, t, full=full) for t in ts)) elif isinstance(ts, dict): return {k: nested_map(func, v, full=full) for (k, v) in ts.items()} elif (isinstance(ts, slice) and full): start = nested_map(func, ts.start, full=full) stop = nested_map(func, ts.stop, full=full) step = nested_map(func, ts.step, full=full) return slice(start, stop, step) return func(ts)
def flatten(ts): if isinstance(ts, torch.Size): (yield ts) elif isinstance(ts, (list, tuple, set)): (yield from chain(*[flatten(t) for t in ts])) elif isinstance(ts, dict): (yield from chain(*[flatten(t) for (k, t) in sorted(ts.items(), key=(lambda t: t[0]))])) else: (yield ts)
def unflatten(xs, structure): return _unflatten(xs, structure)[0]
def _unflatten(xs, structure): if isinstance(structure, torch.Size): return (xs[0], 1) if (not isinstance(structure, (list, tuple, set, dict))): return (xs[0], 1) if isinstance(structure, (list, tuple, set)): offset = 0 elements = [] for s in structure: (e, n) = _unflatten(xs[offset:], s) elements.append(e) offset += n return (type(structure)(elements), offset) assert isinstance(structure, dict) offset = 0 elements = dict() for (k, v) in sorted(structure.items(), key=(lambda t: t[0])): (e, n) = _unflatten(xs[offset:], v) elements[k] = e offset += n return (elements, offset)
def state_dict(partition, *args, **kwargs): state = nn.Module.state_dict(partition, *args, **kwargs) lookup = partition.lookup result = dict() for (k, v) in state.items(): if (k in lookup): result[lookup[k]] = v else: assert ('.' in k) split_idx = k.find('.') new_k = (lookup[k[:split_idx]] + k[split_idx:]) result[new_k] = v return result
def load_state_dict(partition, state): reverse_lookup = {v: k for (k, v) in partition.lookup.items()} device = partition.device keys = list(partition.state_dict(None).keys()) new_state = dict() for k in keys: if (k in reverse_lookup): new_state[reverse_lookup[k]] = state[k].to(device) continue idx = k.rfind('.') to_replace = k[:idx] if (to_replace in reverse_lookup): key = (reverse_lookup[to_replace] + k[idx:]) new_state[key] = state[k].to(device) nn.Module.load_state_dict(partition, new_state, strict=True)
def named_buffers(partition, recurse=True): params = nn.Module.named_buffers(partition, recurse=recurse) lookup = partition.lookup for (k, v) in params: if (k in lookup): (yield (lookup[k], v)) else: assert ('.' in k) split_idx = k.find('.') new_k = (lookup[k[:split_idx]] + k[split_idx:]) (yield (new_k, v))
def named_parameters(partition, recurse=True): params = nn.Module.named_parameters(partition, recurse=recurse) lookup = partition.lookup for (k, v) in params: if (k in lookup): (yield (lookup[k], v)) else: assert ('.' in k) split_idx = k.find('.') new_k = (lookup[k[:split_idx]] + k[split_idx:]) (yield (new_k, v))
def cpu(partition): partition.device = torch.device('cpu') return nn.Module.cpu(partition)
def cuda(partition, device=None): if (device is None): device = torch.cuda.current_device() partition.device = torch.device(device) return nn.Module.cuda(partition, partition.device)
def to(partition, *args, **kwargs): device = None if ('device' in kwargs): device = kwargs['device'] elif ('tensor' in kwargs): device = kwargs['tensor'].device if args: if isinstance(args[0], (torch.device, int, str)): device = args[0] if torch.is_tensor(args[0]): device = args[0].device if (not (device is None)): partition.device = torch.device(device) return nn.Module.to(partition, *args, **kwargs)
def create_pipeline_configuration(DEBUG=False, batch_size=4): config = {'batch_dim': 0, 'depth': 10000, 'basic_blocks': (T5Block, Linear, T5LayerNorm, CrossEntropyLoss, Dropout, StatelessEmbedding), 'model_inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'is_batched': True, 'used_by': [0, 1, 2, 3, 4, 5]}, 'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'is_batched': True, 'used_by': [5, 6, 7]}, 'decoder_input_ids': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'is_batched': True, 'used_by': [0, 5]}, 'input_ids': {'shape': torch.Size([4, 512]), 'dtype': torch.int64, 'is_batched': True, 'used_by': [0]}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'is_batched': True, 'used_by': [5, 6, 7]}, 'lm_labels': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'is_batched': True, 'used_by': [7]}}, 'model_outputs': {'T5ForConditionalGeneration/CrossEntropyLoss[lm_loss]': {'shape': torch.Size([1]), 'dtype': torch.float32, 'is_batched': False, 'created_by': 7}}, 'stages': {0: {'stage_cls': Partition0, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'decoder_input_ids': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'input_ids': {'shape': torch.Size([4, 512]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[decoder]/Tensor::size_117': {'shape': torch.Size([2]), 'dtype': torch.Size, 'req_grad': False, 'is_batched': False, 'used_by': [5]}, 'T5ForConditionalGeneration/Parameter[shared_embed_weight]': {'shape': torch.Size([32100, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': False, 'used_by': [5]}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_1': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [1]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[3]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [1]}}, 'devices': [('cpu' if DEBUG else 'cuda:0')], 'stage_depth': 7}, 1: {'stage_cls': Partition1, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_1': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 0}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[3]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 0}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_2': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [2]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[7]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [2]}}, 'devices': [('cpu' if DEBUG else 'cuda:1')], 'stage_depth': 6}, 2: {'stage_cls': Partition2, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_2': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 1}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[7]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 1}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_3': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [3]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[11]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [3]}}, 'devices': [('cpu' if DEBUG else 'cuda:2')], 'stage_depth': 5}, 3: {'stage_cls': Partition3, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_3': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 2}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[11]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 2}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_4': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [4]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [4]}}, 'devices': [('cpu' if DEBUG else 'cuda:3')], 'stage_depth': 4}, 4: {'stage_cls': Partition4, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_4': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 3}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 3}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_5': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [5]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [5]}}, 'devices': [('cpu' if DEBUG else 'cuda:4')], 'stage_depth': 3}, 5: {'stage_cls': Partition5, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'decoder_input_ids': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[decoder]/Tensor::size_117': {'shape': torch.Size([2]), 'dtype': torch.Size, 'req_grad': False, 'is_batched': False, 'created_by': 0}, 'T5ForConditionalGeneration/Parameter[shared_embed_weight]': {'shape': torch.Size([32100, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': False, 'created_by': 0}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_5': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 4}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 4}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_6': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___128': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_6': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_6': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}}, 'devices': [('cpu' if DEBUG else 'cuda:5')], 'stage_depth': 2}, 6: {'stage_cls': Partition6, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_6': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___128': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_6': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_6': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_7': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_7': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_7': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}}, 'devices': [('cpu' if DEBUG else 'cuda:6')], 'stage_depth': 1}, 7: {'stage_cls': Partition7, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'lm_labels': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_7': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_7': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_7': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}}, 'outputs': {'T5ForConditionalGeneration/CrossEntropyLoss[lm_loss]': {'shape': torch.Size([1]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': False, 'used_by': [(- 1)]}}, 'devices': [('cpu' if DEBUG else 'cuda:7')], 'stage_depth': 0}}} batch_dim = config['batch_dim'] for d in chain(config['model_inputs'].values(), config['model_outputs'].values()): if d['is_batched']: shape = d['shape'] d['shape'] = torch.Size(((shape[:batch_dim] + (batch_size,)) + shape[(batch_dim + 1):])) for s in config['stages'].values(): for d in chain(s['inputs'].values(), s['outputs'].values()): if d['is_batched']: shape = d['shape'] d['shape'] = torch.Size(((shape[:batch_dim] + (batch_size,)) + shape[(batch_dim + 1):])) return config
class Partition0(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/StatelessEmbedding[embed_tokens]', 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[0]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[1]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[2]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[3]'] TENSORS = ['T5ForConditionalGeneration/Parameter[shared_embed_weight]'] def __init__(self, layers, tensors, device='cuda:0'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.embed_tokens', 'l_1': 'encoder.dropout', 'l_2': 'encoder.0', 'l_3': 'encoder.1', 'l_4': 'encoder.2', 'l_5': 'encoder.3', 'p_0': 'shared_embed_weight'} self.to(self.device) def forward(self, *args): (attention_mask, decoder_input_ids, input_ids) = unflatten(args, self.input_structure) t_0 = decoder_input_ids.size() t_1 = input_ids.size() t_1 = t_1[(- 1)] t_1 = input_ids.view((- 1), t_1) t_1 = self.l_0(self.p_0, t_1) t_1 = self.l_1(t_1) t_1 = self.l_2(t_1, attention_mask=attention_mask, position_bias=None, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_2 = t_1[0] t_1 = t_1[1] t_2 = self.l_3(t_2, attention_mask=attention_mask, position_bias=t_1, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_2 = self.l_4(t_2, attention_mask=attention_mask, position_bias=t_1, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_2 = self.l_5(t_2, attention_mask=attention_mask, position_bias=t_1, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((t_0, self.p_0, t_1, t_2))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition1(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[4]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[5]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[6]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[7]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:1'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.4', 'l_1': 'encoder.5', 'l_2': 'encoder.6', 'l_3': 'encoder.7'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_3(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition2(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[8]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[9]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[10]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[11]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:2'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.8', 'l_1': 'encoder.9', 'l_2': 'encoder.10', 'l_3': 'encoder.11'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_3(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition3(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:3'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.12', 'l_1': 'encoder.13', 'l_2': 'encoder.14', 'l_3': 'encoder.15'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_3(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition4(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:4'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.16', 'l_1': 'encoder.17', 'l_2': 'encoder.18', 'l_3': 'encoder.19'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_3(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition5(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5LayerNorm[final_layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/StatelessEmbedding[embed_tokens]', 'T5ForConditionalGeneration/T5Stack[decoder]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:5'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'encoder.20', 'l_1': 'encoder.21', 'l_2': 'encoder.22', 'l_3': 'encoder.23', 'l_4': 'encoder.final_layer_norm', 'l_5': 'encoder.dropout', 'l_6': 'decoder.embed_tokens', 'l_7': 'decoder.dropout', 'l_8': 'decoder.0'} self.to(self.device) def forward(self, *args): (attention_mask, decoder_attention_mask, decoder_input_ids, inverted_encoder_attention_mask, x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x3, attention_mask=attention_mask, position_bias=x2, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x2, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x2, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_3(t_0, attention_mask=attention_mask, position_bias=x2, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_4(t_0) t_0 = self.l_5(t_0) t_1 = x0[(- 1)] t_1 = decoder_input_ids.view((- 1), t_1) t_1 = self.l_6(x1, t_1) t_1 = self.l_7(t_1) t_1 = self.l_8(t_1, attention_mask=decoder_attention_mask, position_bias=None, encoder_hidden_states=t_0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=None) t_2 = t_1[0] t_3 = t_1[1] t_1 = t_1[2] return list(flatten((t_0, t_2, t_3, t_1))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition6(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[10]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[11]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[12]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:6'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.1', 'l_1': 'decoder.2', 'l_2': 'decoder.3', 'l_3': 'decoder.4', 'l_4': 'decoder.5', 'l_5': 'decoder.6', 'l_6': 'decoder.7', 'l_7': 'decoder.8', 'l_8': 'decoder.9', 'l_9': 'decoder.10', 'l_10': 'decoder.11', 'l_11': 'decoder.12'} self.to(self.device) def forward(self, *args): (decoder_attention_mask, inverted_encoder_attention_mask, x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_1(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_2(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_3(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_4(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_5(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_6(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_7(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_8(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_9(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_10(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) t_0 = self.l_11(t_0, attention_mask=decoder_attention_mask, position_bias=x2, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x3) return list(flatten((x0, x2, x3, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition7(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[14]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[15]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[16]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[18]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[19]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[20]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[22]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[23]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5LayerNorm[final_layer_norm]', 'T5ForConditionalGeneration/T5Stack[decoder]/Dropout[dropout]', 'T5ForConditionalGeneration/Linear[lm_head]', 'T5ForConditionalGeneration/CrossEntropyLoss[lm_loss]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:7'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.13', 'l_1': 'decoder.14', 'l_2': 'decoder.15', 'l_3': 'decoder.16', 'l_4': 'decoder.17', 'l_5': 'decoder.18', 'l_6': 'decoder.19', 'l_7': 'decoder.20', 'l_8': 'decoder.21', 'l_9': 'decoder.22', 'l_10': 'decoder.23', 'l_11': 'decoder.final_layer_norm', 'l_12': 'decoder.dropout', 'l_13': 'lm_head', 'l_14': 'lm_loss'} self.to(self.device) def forward(self, *args): (decoder_attention_mask, inverted_encoder_attention_mask, lm_labels, x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x3, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_1(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_2(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_3(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_4(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_5(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_6(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_7(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_8(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_9(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_10(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_11(t_0) t_0 = self.l_12(t_0) t_0 = (t_0 * 0.03125) t_0 = self.l_13(t_0) t_1 = t_0.size((- 1)) t_1 = t_0.view((- 1), t_1) t_0 = lm_labels.view((- 1)) t_0 = self.l_14(t_1, t_0) return (t_0,) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, *args, **kwargs): return load_state_dict(self, *args, **kwargs) def named_parameters(self, *args, **kwargs): return named_parameters(self, *args, **kwargs) def named_buffers(self, *args, **kwargs): return named_buffers(self, *args, **kwargs) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
def traverse_model(module: nn.Module, depth: int, prefix: Optional[str]=None, basic_blocks: Tuple[Type[nn.Module]]=(), full: bool=False) -> Iterator[Tuple[(nn.Module, str, nn.Module, Optional[bool])]]: '\n iterate over model layers yielding the layer,layer_scope,encasing_module\n Parameters:\n -----------\n model:\n the model to iterate over\n depth:\n how far down in the model tree to go\n basic_blocks:\n a list of modules that if encountered will not be broken down\n full:\n whether to yield only layers specified by the depth and basic_block options or to yield all layers\n ' if (prefix is None): prefix = type(module).__name__ for (name, sub_module) in module.named_children(): scope = (((prefix + '/') + type(sub_module).__name__) + f'[{name}]') if ((len(list(sub_module.children())) == 0) or isinstance(sub_module, tuple(basic_blocks)) or (depth == 0)): if full: (yield (sub_module, scope, module, True)) else: (yield (sub_module, scope, module)) else: if full: (yield (sub_module, scope, module, False)) (yield from traverse_model(sub_module, (depth - 1), scope, basic_blocks, full))
def layerDict(model: nn.Module, depth=1000, basic_blocks=()) -> Dict[(str, nn.Module)]: return {s: l for (l, s, _) in traverse_model(model, depth, basic_blocks=basic_blocks)}
def traverse_params_buffs(module: nn.Module, prefix: Optional[str]=None) -> Iterator[Tuple[(torch.tensor, str)]]: "\n iterate over model's buffers and parameters yielding obj,obj_scope\n\n Parameters:\n -----------\n model:\n the model to iterate over\n " if (prefix is None): prefix = type(module).__name__ for (param_name, param) in module.named_parameters(recurse=False): param_scope = f'{prefix}/{type(param).__name__}[{param_name}]' (yield (param, param_scope)) for (buffer_name, buffer) in module.named_buffers(recurse=False): buffer_scope = f'{prefix}/{type(buffer).__name__}[{buffer_name}]' (yield (buffer, buffer_scope)) for (name, sub_module) in module.named_children(): (yield from traverse_params_buffs(sub_module, (((prefix + '/') + type(sub_module).__name__) + f'[{name}]')))
def tensorDict(model: nn.Module) -> OrderedDict[(str, Tensor)]: return collections.OrderedDict(((s, t) for (t, s) in traverse_params_buffs(model)))
def move_tensors(ts, device): def move(t): if isinstance(t, (nn.Module, Tensor)): return t.to(device) return t return nested_map(move, ts)
def nested_map(func, ts, full=False): if isinstance(ts, torch.Size): return func(ts) elif isinstance(ts, (list, tuple, set)): return type(ts)((nested_map(func, t, full=full) for t in ts)) elif isinstance(ts, dict): return {k: nested_map(func, v, full=full) for (k, v) in ts.items()} elif (isinstance(ts, slice) and full): start = nested_map(func, ts.start, full=full) stop = nested_map(func, ts.stop, full=full) step = nested_map(func, ts.step, full=full) return slice(start, stop, step) return func(ts)
def flatten(ts): if isinstance(ts, torch.Size): (yield ts) elif isinstance(ts, (list, tuple, set)): (yield from chain(*[flatten(t) for t in ts])) elif isinstance(ts, dict): (yield from chain(*[flatten(t) for (k, t) in sorted(ts.items(), key=(lambda t: t[0]))])) else: (yield ts)
def unflatten(xs, structure): return _unflatten(xs, structure)[0]
def _unflatten(xs, structure): if isinstance(structure, torch.Size): return (xs[0], 1) if (not isinstance(structure, (list, tuple, set, dict))): return (xs[0], 1) if isinstance(structure, (list, tuple, set)): offset = 0 elements = [] for s in structure: (e, n) = _unflatten(xs[offset:], s) elements.append(e) offset += n return (type(structure)(elements), offset) assert isinstance(structure, dict) offset = 0 elements = dict() for (k, v) in sorted(structure.items(), key=(lambda t: t[0])): (e, n) = _unflatten(xs[offset:], v) elements[k] = e offset += n return (elements, offset)
def state_dict(partition, *args, **kwargs): state = nn.Module.state_dict(partition, *args, **kwargs) lookup = partition.lookup result = dict() for (k, v) in state.items(): if (k in lookup): result[lookup[k]] = v else: assert ('.' in k) split_idx = k.find('.') new_k = (lookup[k[:split_idx]] + k[split_idx:]) result[new_k] = v return result
def load_state_dict(partition, state_dict, strict=True): reverse_lookup = {v: k for (k, v) in partition.lookup.items()} device = partition.device keys = list(partition.state_dict(None).keys()) new_state = dict() for k in keys: if (k in reverse_lookup): new_state[reverse_lookup[k]] = state_dict[k].to(device) continue idx = k.rfind('.') to_replace = k[:idx] if (to_replace in reverse_lookup): key = (reverse_lookup[to_replace] + k[idx:]) new_state[key] = state_dict[k].to(device) nn.Module.load_state_dict(partition, new_state, strict=strict)
def named_buffers(partition, prefix='', recurse=True): params = nn.Module.named_buffers(partition, prefix=prefix, recurse=recurse) lookup = partition.lookup for (k, v) in params: if (k in lookup): (yield (lookup[k], v)) else: assert ('.' in k) split_idx = k.find('.') new_k = (lookup[k[:split_idx]] + k[split_idx:]) (yield (new_k, v))
def named_parameters(partition, prefix='', recurse=True): params = nn.Module.named_parameters(partition, prefix=prefix, recurse=recurse) lookup = partition.lookup for (k, v) in params: if (k in lookup): (yield (lookup[k], v)) else: assert ('.' in k) split_idx = k.find('.') new_k = (lookup[k[:split_idx]] + k[split_idx:]) (yield (new_k, v))
def cpu(partition): partition.device = torch.device('cpu') return nn.Module.cpu(partition)
def cuda(partition, device=None): if (device is None): device = torch.cuda.current_device() partition.device = torch.device(device) return nn.Module.cuda(partition, partition.device)
def to(partition, *args, **kwargs): device = None if ('device' in kwargs): device = kwargs['device'] elif ('tensor' in kwargs): device = kwargs['tensor'].device if args: if isinstance(args[0], (torch.device, int, str)): device = args[0] if torch.is_tensor(args[0]): device = args[0].device if (not (device is None)): partition.device = torch.device(device) return nn.Module.to(partition, *args, **kwargs)
def t5_3b_tied_lmheads_512_4_8p_bw12_squad1_pipedream(): return dict(model_type='t5_stateless', model_name_or_path='t5-3b', do_lower_case=False, output_past=False, stateless_tied=True, explicitly_set_dict={'output_only': True, 'output_attentions': False, 'precompute_masks': True, 'output_hidden_states': False}, do_resize_token_embedding=False)
def create_pipeline_configuration(DEBUG=False, batch_size=4): config = {'batch_dim': 0, 'depth': 10000, 'basic_blocks': (T5LayerNorm, CrossEntropyLoss, T5Block, Dropout, StatelessEmbedding, Linear), 'model_inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'is_batched': True, 'used_by': [0, 1, 2, 3, 4, 5, 6, 7]}, 'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'is_batched': True, 'used_by': [9, 10, 11, 12, 13, 14, 15]}, 'decoder_input_ids': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'is_batched': True, 'used_by': [9]}, 'input_ids': {'shape': torch.Size([4, 512]), 'dtype': torch.int64, 'is_batched': True, 'used_by': [0]}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'is_batched': True, 'used_by': [9, 10, 11, 12, 13, 14, 15]}, 'lm_labels': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'is_batched': True, 'used_by': [15]}}, 'model_outputs': {'T5ForConditionalGeneration/CrossEntropyLoss[lm_loss]': {'shape': torch.Size([1]), 'dtype': torch.float32, 'is_batched': False, 'created_by': 15}}, 'stages': {0: {'stage_cls': Partition0, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'input_ids': {'shape': torch.Size([4, 512]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}}, 'outputs': {'T5ForConditionalGeneration/Parameter[shared_embed_weight]': {'shape': torch.Size([32100, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': False, 'used_by': [9]}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_1': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [1]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[2]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [1]}}, 'devices': [('cpu' if DEBUG else 'cuda:0')], 'stage_depth': 15}, 1: {'stage_cls': Partition1, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_1': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 0}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[2]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 0}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_2': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [2]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[5]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [2]}}, 'devices': [('cpu' if DEBUG else 'cuda:1')], 'stage_depth': 14}, 2: {'stage_cls': Partition2, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_2': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 1}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[5]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 1}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_3': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [3]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[8]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [3]}}, 'devices': [('cpu' if DEBUG else 'cuda:2')], 'stage_depth': 13}, 3: {'stage_cls': Partition3, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_3': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 2}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[8]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 2}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_4': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [4]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[11]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [4]}}, 'devices': [('cpu' if DEBUG else 'cuda:3')], 'stage_depth': 12}, 4: {'stage_cls': Partition4, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_4': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 3}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[11]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 3}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_5': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [5]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [5]}}, 'devices': [('cpu' if DEBUG else 'cuda:4')], 'stage_depth': 11}, 5: {'stage_cls': Partition5, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_5': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 4}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 4}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_6': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [6]}}, 'devices': [('cpu' if DEBUG else 'cuda:5')], 'stage_depth': 10}, 6: {'stage_cls': Partition6, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_6': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 5}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_7': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [7]}}, 'devices': [('cpu' if DEBUG else 'cuda:6')], 'stage_depth': 9}, 7: {'stage_cls': Partition7, 'inputs': {'attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/tuple::__getitem___22_7': {'shape': torch.Size([4, 32, 512, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}, 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 6}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [8]}}, 'devices': [('cpu' if DEBUG else 'cuda:7')], 'stage_depth': 8}, 8: {'stage_cls': Partition8, 'inputs': {'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 7}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_9': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [9]}}, 'devices': [('cpu' if DEBUG else 'cuda:8')], 'stage_depth': 7}, 9: {'stage_cls': Partition9, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'decoder_input_ids': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/Parameter[shared_embed_weight]': {'shape': torch.Size([32100, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': False, 'created_by': 0}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_9': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 8}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_10': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [10]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_10': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [10]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_10': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [10]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [10]}}, 'devices': [('cpu' if DEBUG else 'cuda:9')], 'stage_depth': 6}, 10: {'stage_cls': Partition10, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_10': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 9}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_10': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 9}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_10': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 9}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 9}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_11': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [11]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_11': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [11]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_11': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [11]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [11]}}, 'devices': [('cpu' if DEBUG else 'cuda:10')], 'stage_depth': 5}, 11: {'stage_cls': Partition11, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_11': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 10}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_11': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 10}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_11': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 10}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 10}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_12': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [12]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_12': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [12]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_12': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [12]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [12]}}, 'devices': [('cpu' if DEBUG else 'cuda:11')], 'stage_depth': 4}, 12: {'stage_cls': Partition12, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_12': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 11}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_12': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 11}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_12': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 11}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 11}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_13': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [13]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_13': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [13]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_13': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [13]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [13]}}, 'devices': [('cpu' if DEBUG else 'cuda:12')], 'stage_depth': 3}, 13: {'stage_cls': Partition13, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_13': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 12}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_13': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 12}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_13': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 12}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[13]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 12}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_14': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [14]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_14': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [14]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_14': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [14]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [14]}}, 'devices': [('cpu' if DEBUG else 'cuda:13')], 'stage_depth': 2}, 14: {'stage_cls': Partition14, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_14': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 13}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_14': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 13}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_14': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 13}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[17]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 13}}, 'outputs': {'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_15': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [15]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_15': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [15]}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_15': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [15]}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'used_by': [15]}}, 'devices': [('cpu' if DEBUG else 'cuda:14')], 'stage_depth': 1}, 15: {'stage_cls': Partition15, 'inputs': {'decoder_attention_mask': {'shape': torch.Size([4, 1, 4, 4]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'inverted_encoder_attention_mask': {'shape': torch.Size([4, 1, 1, 512]), 'dtype': torch.float32, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'lm_labels': {'shape': torch.Size([4, 4]), 'dtype': torch.int64, 'req_grad': False, 'is_batched': True, 'created_by': (- 1)}, 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]_15': {'shape': torch.Size([4, 512, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 14}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___130_15': {'shape': torch.Size([4, 32, 4, 4]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 14}, 'T5ForConditionalGeneration/T5Stack[decoder]/tuple::__getitem___132_15': {'shape': torch.Size([4, 32, 4, 512]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 14}, 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[21]': {'shape': torch.Size([4, 4, 1024]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': True, 'created_by': 14}}, 'outputs': {'T5ForConditionalGeneration/CrossEntropyLoss[lm_loss]': {'shape': torch.Size([1]), 'dtype': torch.float32, 'req_grad': True, 'is_batched': False, 'used_by': [(- 1)]}}, 'devices': [('cpu' if DEBUG else 'cuda:15')], 'stage_depth': 0}}} batch_dim = config['batch_dim'] for d in chain(config['model_inputs'].values(), config['model_outputs'].values()): if d['is_batched']: shape = d['shape'] d['shape'] = torch.Size(((shape[:batch_dim] + (batch_size,)) + shape[(batch_dim + 1):])) for s in config['stages'].values(): for d in chain(s['inputs'].values(), s['outputs'].values()): if d['is_batched']: shape = d['shape'] d['shape'] = torch.Size(((shape[:batch_dim] + (batch_size,)) + shape[(batch_dim + 1):])) return config
class Partition0(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/StatelessEmbedding[embed_tokens]', 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[0]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[1]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[2]'] TENSORS = ['T5ForConditionalGeneration/Parameter[shared_embed_weight]'] def __init__(self, layers, tensors, device='cuda:0'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1] self.lookup = {'l_0': 'encoder.embed_tokens', 'l_1': 'encoder.dropout', 'l_2': 'encoder.0', 'l_3': 'encoder.1', 'l_4': 'encoder.2', 'p_0': 'shared_embed_weight'} self.to(self.device) def forward(self, *args): (attention_mask, input_ids) = unflatten(args, self.input_structure) t_0 = input_ids.size() t_0 = t_0[(- 1)] t_0 = input_ids.view((- 1), t_0) t_0 = self.l_0(self.p_0, t_0) t_0 = self.l_1(t_0) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=None, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_1 = t_0[0] t_0 = t_0[1] t_1 = self.l_3(t_1, attention_mask=attention_mask, position_bias=t_0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_1 = self.l_4(t_1, attention_mask=attention_mask, position_bias=t_0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((self.p_0, t_0, t_1))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition1(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[3]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[4]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[5]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:1'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.3', 'l_1': 'encoder.4', 'l_2': 'encoder.5'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition2(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[6]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[7]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[8]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:2'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.6', 'l_1': 'encoder.7', 'l_2': 'encoder.8'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition3(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[9]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[10]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[11]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:3'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.9', 'l_1': 'encoder.10', 'l_2': 'encoder.11'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition4(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[12]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[13]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[14]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:4'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.12', 'l_1': 'encoder.13', 'l_2': 'encoder.14'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition5(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[15]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[16]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[17]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:5'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.15', 'l_1': 'encoder.16', 'l_2': 'encoder.17'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition6(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[18]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[19]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[20]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:6'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.18', 'l_1': 'encoder.19', 'l_2': 'encoder.20'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return list(flatten((x0, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition7(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5Block[21]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[22]', 'T5ForConditionalGeneration/T5Stack[encoder]/T5Block[23]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:7'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1] self.lookup = {'l_0': 'encoder.21', 'l_1': 'encoder.22', 'l_2': 'encoder.23'} self.to(self.device) def forward(self, *args): (attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = self.l_0(x1, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_1(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) t_0 = self.l_2(t_0, attention_mask=attention_mask, position_bias=x0, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None) return (t_0,) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition8(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[encoder]/T5LayerNorm[final_layer_norm]', 'T5ForConditionalGeneration/T5Stack[encoder]/Dropout[dropout]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:8'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1] self.lookup = {'l_0': 'encoder.final_layer_norm', 'l_1': 'encoder.dropout'} self.to(self.device) def forward(self, *args): x0 = unflatten(args, self.input_structure)[0] t_0 = self.l_0(x0) t_0 = self.l_1(t_0) return (t_0,) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition9(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/StatelessEmbedding[embed_tokens]', 'T5ForConditionalGeneration/T5Stack[decoder]/Dropout[dropout]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[0]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[1]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:9'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.embed_tokens', 'l_1': 'decoder.dropout', 'l_2': 'decoder.0', 'l_3': 'decoder.1'} self.to(self.device) def forward(self, *args): (decoder_attention_mask, decoder_input_ids, inverted_encoder_attention_mask, x0, x1) = unflatten(args, self.input_structure) t_0 = decoder_input_ids.size() t_0 = t_0[(- 1)] t_0 = decoder_input_ids.view((- 1), t_0) t_0 = self.l_0(x0, t_0) t_0 = self.l_1(t_0) t_0 = self.l_2(t_0, attention_mask=decoder_attention_mask, position_bias=None, encoder_hidden_states=x1, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=None) t_1 = t_0[0] t_2 = t_0[1] t_0 = t_0[2] t_1 = self.l_3(t_1, attention_mask=decoder_attention_mask, position_bias=t_2, encoder_hidden_states=x1, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=t_0) return list(flatten((x1, t_2, t_0, t_1))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition10(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[2]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[3]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[4]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[5]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:10'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.2', 'l_1': 'decoder.3', 'l_2': 'decoder.4', 'l_3': 'decoder.5'} self.to(self.device) def forward(self, *args): (decoder_attention_mask, inverted_encoder_attention_mask, x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x3, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_1(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_2(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_3(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) return list(flatten((x0, x1, x2, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)
class Partition11(nn.Module): LAYER_SCOPES = ['T5ForConditionalGeneration/T5Stack[decoder]/T5Block[6]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[7]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[8]', 'T5ForConditionalGeneration/T5Stack[decoder]/T5Block[9]'] TENSORS = [] def __init__(self, layers, tensors, device='cuda:11'): super().__init__() for (idx, layer_scope) in enumerate(self.LAYER_SCOPES): self.add_module(f'l_{idx}', layers[layer_scope]) b = p = 0 for tensor_scope in self.TENSORS: tensor = tensors[tensor_scope] if isinstance(tensor, nn.Parameter): self.register_parameter(f'p_{p}', tensor) p += 1 else: self.register_buffer(f'b_{b}', tensor) b += 1 self.device = torch.device(device) self.input_structure = [1, 1, 1, 1, 1, 1] self.lookup = {'l_0': 'decoder.6', 'l_1': 'decoder.7', 'l_2': 'decoder.8', 'l_3': 'decoder.9'} self.to(self.device) def forward(self, *args): (decoder_attention_mask, inverted_encoder_attention_mask, x0, x1, x2, x3) = unflatten(args, self.input_structure) t_0 = self.l_0(x3, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_1(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_2(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) t_0 = self.l_3(t_0, attention_mask=decoder_attention_mask, position_bias=x1, encoder_hidden_states=x0, encoder_attention_mask=inverted_encoder_attention_mask, encoder_decoder_position_bias=x2) return list(flatten((x0, x1, x2, t_0))) def state_dict(self, *args, **kwargs): return state_dict(self, *args, **kwargs) def load_state_dict(self, state): return load_state_dict(self, state) def named_parameters(self, recurse=True): return named_parameters(self, recurse=recurse) def named_buffers(self, recurse=True): return named_buffers(self, recurse=recurse) def cpu(self): return cpu(self) def cuda(self, device=None): return cuda(self, device=device) def to(self, *args, **kwargs): return to(self, *args, **kwargs)