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

Method __init__

examples/pytorch/longformer/model.py:61–78  ·  view source on GitHub ↗
(self, weights_file, layer_num, head_num, size_per_head,
                 intermediate_size, local_attn_window_size,
                 max_global_token_num, batch_size, seq_len,
                 attn_scaler, ft_longformer_lib, data_type='fp32', hf_plugin_mode=False)

Source from the content-addressed store, hash-verified

59
60class FTLongformerEncoder(torch.nn.Module):
61 def __init__(self, weights_file, layer_num, head_num, size_per_head,
62 intermediate_size, local_attn_window_size,
63 max_global_token_num, batch_size, seq_len,
64 attn_scaler, ft_longformer_lib, data_type='fp32', hf_plugin_mode=False):
65 super().__init__()
66 self.data_type = data_type
67 assert seq_len % local_attn_window_size == 0 and seq_len / \
68 local_attn_window_size >= 2, "seq_len need to be multiple of local_attn_window_size and at least 2 times big."
69
70 self.hf_plugin_mode = hf_plugin_mode
71 all_weight = from_hf_longformer_weight_to_ft(weights_file, layer_num, data_type)
72 self.all_weight = all_weight.cuda()
73 torch.classes.load_library(ft_longformer_lib)
74 self.ft_encoder = torch.classes.FasterTransformer.LongformerEncoder(layer_num, head_num * size_per_head,
75 head_num, size_per_head,
76 intermediate_size, local_attn_window_size,
77 max_global_token_num, batch_size, seq_len,
78 attn_scaler)
79
80 def set_hf_plugin_mode(self, is_plugin):
81 self.hf_plugin_mode = is_plugin

Callers

nothing calls this directly

Calls 3

LongformerEncoderMethod · 0.80
cudaMethod · 0.45

Tested by

no test coverage detected