(layer_num, batch_size, beam_width, max_seq_len, \
decoding_max_seq_len, head_num, size_per_head, hidden_dim, is_fp16)
| 28 | return use_batch_major_op_cache, x |
| 29 | |
| 30 | def init_op_cache(layer_num, batch_size, beam_width, max_seq_len, \ |
| 31 | decoding_max_seq_len, head_num, size_per_head, hidden_dim, is_fp16): |
| 32 | use_batch_major_op_cache, x = get_op_cache_config(size_per_head, is_fp16) |
| 33 | dtype = torch.half if is_fp16 else torch.float32 |
| 34 | if use_batch_major_op_cache == True: |
| 35 | self_cache = [ torch.zeros(layer_num, batch_size * beam_width, head_num, size_per_head // x, |
| 36 | decoding_max_seq_len, x, dtype=dtype, device='cuda'), |
| 37 | torch.zeros(layer_num, batch_size * beam_width, head_num, |
| 38 | decoding_max_seq_len, size_per_head, dtype=dtype, device='cuda') ] |
| 39 | else: |
| 40 | self_cache = [ torch.zeros(layer_num, 0, batch_size * beam_width, hidden_dim, dtype=dtype, device='cuda'), |
| 41 | torch.zeros(layer_num, 0, batch_size * beam_width, hidden_dim, dtype=dtype, device='cuda') ] |
| 42 | |
| 43 | # always use old format for cross attention for now |
| 44 | mem_cache = torch.zeros(2, layer_num, batch_size * beam_width, max_seq_len, hidden_dim, dtype=dtype, device='cuda') |
| 45 | |
| 46 | return self_cache, mem_cache |
| 47 | |
| 48 | def init_onmt_cache(layer_num, memory_bank): |
| 49 | cache = {} |
no test coverage detected