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

Function make_viewless_tensor

DeepSpeedExample/megatron/core/utils.py:111–129  ·  view source on GitHub ↗

Entry-point for creating viewless tensors. This method should be used, rather than calling 'MakeViewlessTensor' or '_kernel_make_viewless_tensor' directly. This method acts as a switch for determining if an autograd function or a regular method should be used to create the tens

(inp, requires_grad, keep_graph)

Source from the content-addressed store, hash-verified

109 return grad_output, None
110
111def make_viewless_tensor(inp, requires_grad, keep_graph):
112 '''
113 Entry-point for creating viewless tensors.
114
115 This method should be used, rather than calling 'MakeViewlessTensor'
116 or '_kernel_make_viewless_tensor' directly. This method acts as a
117 switch for determining if an autograd function or a regular method
118 should be used to create the tensor.
119 '''
120
121 # return tensor as-is, if not a 'view'
122 if inp._base is None:
123 return inp
124
125 # create viewless tensor
126 if keep_graph:
127 return MakeViewlessTensor.apply(inp, requires_grad)
128 else:
129 return _kernel_make_viewless_tensor(inp, requires_grad)
130
131def assert_viewless_tensor(tensor, extra_msg = None):
132 '''Assert that a tensor is not a view (i.e., its '._base' field is

Callers 3

forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90

Calls 2

applyMethod · 0.45

Tested by

no test coverage detected