MCPcopy Index your code
hub / github.com/pytorch/pytorch / Caffe2LSTM

Function Caffe2LSTM

caffe2/python/lstm_benchmark.py:163–230  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

161
162
163def Caffe2LSTM(args):
164 T = args.data_size // args.batch_size
165
166 input_blob_shape = [args.seq_length, args.batch_size, args.input_dim]
167 queue, label_queue, entry_counts = generate_data(T // args.seq_length,
168 input_blob_shape,
169 args.hidden_dim,
170 args.fixed_shape)
171
172 workspace.FeedBlob(
173 "seq_lengths",
174 np.array([args.seq_length] * args.batch_size, dtype=np.int32)
175 )
176
177 model, output = create_model(args, queue, label_queue, input_blob_shape)
178
179 workspace.RunNetOnce(model.param_init_net)
180 workspace.CreateNet(model.net)
181
182 start_time = time.time()
183 num_iters = T // args.seq_length
184 total_iters = 0
185
186 # Run the Benchmark
187 log.info("------ Warming up ------")
188 workspace.RunNet(model.net.Proto().name)
189
190 if (args.gpu):
191 log.info("Memory stats:")
192 stats = utils.GetGPUMemoryUsageStats()
193 log.info("GPU memory:\t{} MB".format(stats['max_total'] / 1024 / 1024))
194
195 log.info("------ Starting benchmark ------")
196 start_time = time.time()
197 last_time = time.time()
198 for iteration in range(1, num_iters, args.iters_to_report):
199 iters_once = min(args.iters_to_report, num_iters - iteration)
200 total_iters += iters_once
201 workspace.RunNet(model.net.Proto().name, iters_once)
202
203 new_time = time.time()
204 log.info(
205 "Iter: {} / {}. Entries Per Second: {}k.".format(
206 iteration,
207 num_iters,
208 np.sum(entry_counts[iteration:iteration + iters_once]) /
209 (new_time - last_time) // 100 / 10,
210 )
211 )
212 last_time = new_time
213
214 log.info("Done. Total EPS excluding 1st iteration: {}k {}".format(
215 np.sum(entry_counts[1:]) / (time.time() - start_time) // 100 / 10,
216 " (with RNN executor)" if args.rnn_executor else "",
217 ))
218
219 if (args.gpu):
220 log.info("Memory stats:")

Callers 1

BenchmarkFunction · 0.85

Calls 9

infoMethod · 0.80
warningMethod · 0.80
generate_dataFunction · 0.70
create_modelFunction · 0.70
rangeFunction · 0.50
minFunction · 0.50
ProtoMethod · 0.45
formatMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…