MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _EmbeddingParams

Function _EmbeddingParams

tensorflow/python/kernel_tests/embedding_ops_test.py:139–166  ·  view source on GitHub ↗
(num_shards,
                     vocab_size,
                     dtype=dtypes.float32,
                     shape=None,
                     use_shapeless_placeholder=False)

Source from the content-addressed store, hash-verified

137
138
139def _EmbeddingParams(num_shards,
140 vocab_size,
141 dtype=dtypes.float32,
142 shape=None,
143 use_shapeless_placeholder=False):
144 p = []
145 params = {}
146 feed_dict = {}
147 if not shape:
148 shape = [10]
149 for i in range(num_shards):
150 shard_shape = [vocab_size // num_shards] + shape
151 if i < vocab_size % num_shards: # Excess goes evenly on the first shards
152 shard_shape[0] += 1
153
154 param_name = _PName(i)
155
156 if use_shapeless_placeholder:
157 param = array_ops.placeholder(dtype, shape=None, name=param_name)
158 else:
159 param = constant_op.constant(
160 1.0, shape=shard_shape, dtype=dtype, name=param_name)
161 p.append(param)
162 np_type = "f" if dtype == dtypes.float32 else "d"
163 val = (np.random.rand(*shard_shape).astype(np_type)) + 1
164 params[param_name + ":0"] = val
165 feed_dict[param.name] = val
166 return p, params, feed_dict
167
168
169def _EmbeddingParamsAsPartitionedVariable(num_shards,

Calls 6

randMethod · 0.80
_PNameFunction · 0.70
rangeFunction · 0.50
placeholderMethod · 0.45
constantMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected