MCPcopy Create free account
hub / github.com/THUDM/GLM / convert_module

Function convert_module

fp16/fp16util.py:61–74  ·  view source on GitHub ↗

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

(module, dtype)

Source from the content-addressed store, hash-verified

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

Callers 1

convert_networkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected