(num_shards,
vocab_size,
dtype=dtypes.float32,
shape=None,
use_shapeless_placeholder=False)
| 137 | |
| 138 | |
| 139 | def _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 | |
| 169 | def _EmbeddingParamsAsPartitionedVariable(num_shards, |
no test coverage detected