(res_block, path)
| 6 | from tinygrad.nn import Conv2d |
| 7 | |
| 8 | def save_res_block(res_block, path): |
| 9 | pathlib.Path(path).mkdir(parents=True, exist_ok=True) |
| 10 | # We can't directly save activation functions, but as they are just attribute of the block, |
| 11 | # we don't need to save them separately, they will be recreated along with the block. |
| 12 | |
| 13 | # saving group normalization layer |
| 14 | save_group_norm(res_block.in_layers[0], os.path.join(path, 'norm_in')) |
| 15 | |
| 16 | # saving the convolutional layer |
| 17 | save_conv2d(res_block.in_layers[2], os.path.join(path, 'conv_in')) |
| 18 | |
| 19 | # saving the linear layer |
| 20 | save_linear(res_block.emb_layers[1], os.path.join(path, 'lin_embed')) |
| 21 | |
| 22 | # saving group normalization in out_layers |
| 23 | save_group_norm(res_block.out_layers[0], os.path.join(path, 'norm_out')) |
| 24 | |
| 25 | # saving the convolutional layer in out_layers |
| 26 | save_conv2d(res_block.out_layers[3], os.path.join(path, 'conv_out')) |
| 27 | |
| 28 | # save skip_connection based on the object type |
| 29 | if isinstance(res_block.skip_connection, Conv2d): |
| 30 | save_conv2d(res_block.skip_connection, os.path.join(path, 'skip_connection')) |
| 31 | |
| 32 | def save_cross_attention(cross_attention, path): |
| 33 | pathlib.Path(path).mkdir(parents=True, exist_ok=True) |
no test coverage detected