MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / tensor_builder

Function tensor_builder

python/oneflow/test/modules/test_fused_glu.py:86–120  ·  view source on GitHub ↗
(params: dict, dtype=flow.float32, is_split_mode=True)

Source from the content-addressed store, hash-verified

84
85
86def tensor_builder(params: dict, dtype=flow.float32, is_split_mode=True):
87 # config test data
88 m = params["m"]
89 n = params["n"]
90 k = params["k"]
91
92 # generate random input
93 x = np.random.randn(2, m, k) / 100
94 y_nor = np.random.randn(2, m, n)
95 if is_split_mode:
96 w = np.random.randn(n, k) / 100 # transpose
97 b = np.random.randn(n) / 100
98 v = np.random.randn(n, k) / 100 # transpose
99 c = np.random.randn(n) / 100
100 else:
101 w = np.random.randn(n * 2, k) / 100 # transpose
102 b = np.random.randn(n * 2) / 100
103
104 # transfer to gpu memory
105 tensor_x = flow.FloatTensor(x).to(dtype=dtype, device="cuda")
106 tensor_y_nor = flow.FloatTensor(y_nor).to(dtype=dtype, device="cuda")
107 tensor_w = flow.FloatTensor(w).to(dtype=dtype, device="cuda").requires_grad_(True)
108 tensor_b = flow.FloatTensor(b).to(dtype=dtype, device="cuda").requires_grad_(True)
109 if is_split_mode:
110 tensor_v = (
111 flow.FloatTensor(v).to(dtype=dtype, device="cuda").requires_grad_(True)
112 )
113 tensor_c = (
114 flow.FloatTensor(c).to(dtype=dtype, device="cuda").requires_grad_(True)
115 )
116
117 if is_split_mode:
118 return tensor_x, tensor_w, tensor_b, tensor_v, tensor_c, tensor_y_nor
119 else:
120 return tensor_x, tensor_w, tensor_b, tensor_y_nor
121
122
123def compare_result(test_case, a, b, rtol=1e-5, atol=1e-8):

Callers 4

_test_fused_gluFunction · 0.85
_test_fused_glu_splitFunction · 0.85

Calls 2

requires_grad_Method · 0.80
toMethod · 0.45

Tested by

no test coverage detected