MCPcopy Create free account
hub / github.com/bytedance/ABQ-LLM / bertExample

Function bertExample

fastertransformer/examples/cpp/bert/bert_example.cc:66–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65template<typename T>
66int bertExample(
67 size_t batch_size, size_t num_layers, size_t seq_len, size_t head_num, size_t size_per_head, bool is_remove_padding)
68{
69 printf("[INFO] Device: %s \n", getDeviceName().c_str());
70 print_mem_usage("Before loading model");
71 const size_t hidden_units = head_num * size_per_head;
72 const size_t inter_size = 4 * hidden_units;
73
74 cudaStream_t stream;
75 cublasHandle_t cublas_handle;
76 cublasLtHandle_t cublaslt_handle;
77 cudaStreamCreate(&stream);
78 cublasCreate(&cublas_handle);
79 cublasLtCreate(&cublaslt_handle);
80#ifdef SPARSITY_ENABLED
81 cusparseLtHandle_t cusparselt_handle;
82 CHECK_CUSPARSE(cusparseLtInit(&cusparselt_handle));
83#endif
84 cublasSetStream(cublas_handle, stream);
85 cublasAlgoMap* cublas_algo_map = new cublasAlgoMap("gemm_config.in", "");
86
87 Allocator<AllocatorType::CUDA> allocator(getDevice());
88
89 std::mutex* cublas_wrapper_mutex = new std::mutex();
90#ifdef SPARSITY_ENABLED
91 cublasMMWrapper cublas_wrapper = cublasMMWrapper(
92 cublas_handle, cublaslt_handle, cusparselt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, &allocator);
93#else
94 cublasMMWrapper cublas_wrapper =
95 cublasMMWrapper(cublas_handle, cublaslt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, &allocator);
96#endif
97 if (std::is_same<T, half>::value) {
98 cublas_wrapper.setFP16GemmConfig();
99 }
100#ifdef ENABLE_BF16
101 else if (std::is_same<T, __nv_bfloat16>::value) {
102 cublas_wrapper.setBF16GemmConfig();
103 }
104#endif
105 else if (std::is_same<T, float>::value) {
106 cublas_wrapper.setFP32GemmConfig();
107 }
108
109 BertWeight<T> bert_weights(hidden_units, inter_size, num_layers);
110
111 AttentionType attention_type = getAttentionType<T>(size_per_head, getSMVersion(), is_remove_padding, seq_len);
112
113 Bert<T> bert = Bert<T>(0, // max_batch_size_, deprecated
114 0, // max_seq_len_, deprecated
115 head_num,
116 size_per_head,
117 inter_size,
118 num_layers,
119 getSMVersion(),
120 1.0f,
121 stream,
122 &cublas_wrapper,
123 &allocator,

Callers

nothing calls this directly

Calls 9

getDeviceNameFunction · 0.85
print_mem_usageFunction · 0.85
getDeviceFunction · 0.85
cublasMMWrapperClass · 0.85
getSMVersionFunction · 0.85
setFP16GemmConfigMethod · 0.80
forwardMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected