MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / init_tf_cache

Function init_tf_cache

examples/tensorflow/decoder/utils/decoder.py:281–301  ·  view source on GitHub ↗
(batch_size,
                  head_num,
                  size_per_head,
                  num_layer,
                  dtype,
                  num_sources=1)

Source from the content-addressed store, hash-verified

279
280
281def init_tf_cache(batch_size,
282 head_num,
283 size_per_head,
284 num_layer,
285 dtype,
286 num_sources=1):
287 cache = {}
288 for l in range(num_layer):
289 proj_cache_shape = [batch_size, head_num, 0, size_per_head]
290 layer_cache = {}
291 layer_cache["memory"] = [
292 {
293 "memory_keys": tf.zeros(proj_cache_shape, dtype=dtype, name="memory_keys"),
294 "memory_values": tf.zeros(proj_cache_shape, dtype=dtype, name="memory_values")
295 } for _ in range(num_sources)]
296 layer_cache["self_keys"] = tf.zeros(
297 proj_cache_shape, dtype=dtype, name="self_keys")
298 layer_cache["self_values"] = tf.zeros(
299 proj_cache_shape, dtype=dtype, name="self_values")
300 cache["layer_{}".format(l)] = layer_cache
301 return cache
302
303
304def init_op_cache(decoder_args, batchxbeam, memory_max_seq_len, decoding_max_seq_len):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected