Код: Выделить всё
for i in range(263):
states = torch.rand(128, 4, 20, 20, device = device)
# time.sleep(1)
start_time = time.time()
policy, value, action_value = model(states)
end_time = time.time()
total_time = end_time - start_time
print(f"time cost:{total_time:.4f} second")
Код: Выделить всё
time cost:0.0003 second
time cost:0.0003 second
time cost:0.0003 second
...
Код: Выделить всё
time cost:0.0008 second
time cost:0.0009 second
time cost:0.0009 second
Код: Выделить всё
std::shared_ptr results_tensor = std::make_shared();
std::shared_ptr model;
while(true)
{
auto start = std::chrono::high_resolution_clock::now();
*results_tensor = nn.model->forward({input});
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration duration = end - start;
{
std::lock_guard lock(cout_mutex);
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79360980/what-caused-the-large-difference-in-execution-time-between-these-two-forward-pas[/url]
Мобильная версия