MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / convert_module

Function convert_module

DeepSpeedExample/megatron/fp16/fp16util.py:64–77  ·  view source on GitHub ↗

Converts a module's immediate parameters and buffers to dtype.

(module, dtype)

Source from the content-addressed store, hash-verified

62
63
64def 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
80def convert_network(network, dtype):

Callers 1

convert_networkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected