Converts a module's immediate parameters and buffers to dtype.
(module, dtype)
| 62 | |
| 63 | |
| 64 | def convert_module(module, dtype): |
| 65 | """ |
| 66 | Converts a module's immediate parameters and buffers to dtype. |
| 67 | """ |
| 68 | for param in module.parameters(recurse=False): |
| 69 | if param is not None: |
| 70 | if param.data.dtype.is_floating_point: |
| 71 | param.data = param.data.to(dtype=dtype) |
| 72 | if param._grad is not None and param._grad.data.dtype.is_floating_point: |
| 73 | param._grad.data = param._grad.data.to(dtype=dtype) |
| 74 | |
| 75 | for buf in module.buffers(recurse=False): |
| 76 | if buf is not None and buf.data.dtype.is_floating_point: |
| 77 | buf.data = buf.data.to(dtype=dtype) |
| 78 | |
| 79 | |
| 80 | def convert_network(network, dtype): |