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

Function gptj_example

examples/cpp/gptj/gptj_example.cc:76–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74
75template<typename T>
76void gptj_example(const INIReader reader)
77{
78 print_mem_usage("Before loading model");
79 const std::string model_name = reader.Get("ft_instance_hyperparameter", "model_name");
80 const size_t max_seq_len = reader.GetInteger("ft_instance_hyperparameter", "max_seq_len");
81 const size_t beam_width = reader.GetInteger("ft_instance_hyperparameter", "beam_width");
82 const uint top_k = (uint)reader.GetInteger("ft_instance_hyperparameter", "top_k");
83 const float top_p = reader.GetFloat("ft_instance_hyperparameter", "top_p");
84 const float temperature = reader.GetFloat("ft_instance_hyperparameter", "temperature");
85 const float repetition_penalty = reader.GetFloat("ft_instance_hyperparameter", "repetition_penalty", 1.0f);
86 const float presence_penalty = reader.GetFloat("ft_instance_hyperparameter", "presence_penalty", 0.0f);
87 const float len_penalty = reader.GetFloat("ft_instance_hyperparameter", "len_penalty");
88 const int min_length = reader.GetInteger("ft_instance_hyperparameter", "min_length", 0);
89 const float beam_search_diversity_rate =
90 reader.GetFloat("ft_instance_hyperparameter", "beam_search_diversity_rate");
91 std::string model_dir = std::string(reader.Get("ft_instance_hyperparameter", "model_dir"));
92
93 int tensor_para_size = reader.GetInteger("ft_instance_hyperparameter", "tensor_para_size");
94 int pipeline_para_size = reader.GetInteger("ft_instance_hyperparameter", "pipeline_para_size");
95
96 const size_t head_num = reader.GetInteger(model_name, "head_num");
97 const size_t size_per_head = reader.GetInteger(model_name, "size_per_head");
98 const size_t vocab_size = reader.GetInteger(model_name, "vocab_size");
99 const size_t decoder_layers = reader.GetInteger(model_name, "decoder_layers");
100 const size_t rotary_embedding_dim = reader.GetInteger(model_name, "rotary_embedding");
101 const int start_id = reader.GetInteger(model_name, "start_id");
102 const int end_id = reader.GetInteger(model_name, "end_id");
103
104 const size_t hidden_units = head_num * size_per_head;
105 const size_t inter_size = reader.GetInteger(model_name, "inter_size");
106
107 const size_t request_batch_size = reader.GetInteger("request", "request_batch_size");
108 // The length of tokens we hope this model to generate
109 const int request_output_len = reader.GetInteger("request", "request_output_len");
110 const uint32_t memory_len = reader.GetInteger("request", "memory_len", 0);
111
112 FT_CHECK(head_num % tensor_para_size == 0);
113 FT_CHECK(decoder_layers % pipeline_para_size == 0);
114 FT_CHECK_WITH_INFO(
115 repetition_penalty == 1.0f || presence_penalty == 0.0f,
116 fmtstr("Found ambiguous parameters repetition_penalty (%f) and presence_penalty (%f) "
117 "which are mutually exclusive. Please remove one of repetition_penalty or presence_penalty "
118 "or set to a default value.",
119 repetition_penalty,
120 presence_penalty));
121
122 // Prepare the parallelism parameters
123 int rank = mpi::getCommWorldRank();
124 int world_size = mpi::getCommWorldSize();
125 if (rank == 0) {
126 printf("Total ranks: %d.\n", world_size);
127 }
128 int device, device_count;
129 check_cuda_error(cudaGetDeviceCount(&device_count));
130 check_cuda_error(cudaSetDevice(rank % device_count));
131 check_cuda_error(cudaGetDevice(&device));
132
133 struct cudaDeviceProp prop;

Callers

nothing calls this directly

Calls 15

print_mem_usageFunction · 0.85
fmtstrFunction · 0.85
getCommWorldRankFunction · 0.85
getCommWorldSizeFunction · 0.85
ftNcclInitializeFunction · 0.85
read_word_listFunction · 0.85
getDeviceFunction · 0.85
cublasMMWrapperClass · 0.85
bcastFunction · 0.85
getSMVersionFunction · 0.85
setScopeFunction · 0.85
resetScopeFunction · 0.85

Tested by

no test coverage detected