Performance

Inference for one Scenario

scenario = socialforce.scenarios.Circle().generate(1)
true_experience = socialforce.Trainer.scenes_to_experience(scenario)
V = socialforce.potentials.PedPedPotentialMLP()

simulator = socialforce.Simulator(ped_ped=V)
opt = torch.optim.SGD(V.parameters(), lr=3.0)
with cProfile.Profile() as pr:
    socialforce.Trainer(simulator, opt).loop(10, true_experience, log_interval=10)
INFO:socialforce.trainer:from 1 scenes, extracted 21 experiences, filtered to 6
epoch 10: 0.009362216029937068
ps = pstats.Stats(pr).strip_dirs().sort_stats('tottime')
ps.dump_stats('simulator.prof')
ps.print_stats()
         117678 function calls (114078 primitive calls) in 1.501 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      660    0.728    0.001    0.728    0.001 {method 'run_backward' of 'torch._C._EngineBase' objects}
     1200    0.095    0.000    0.121    0.000 stateutils.py:6(desired_directions)
      600    0.069    0.000    0.073    0.000 simulator.py:187(__call__)
     4200    0.063    0.000    0.063    0.000 {built-in method torch._C._linalg.linalg_norm}
      600    0.047    0.000    0.930    0.002 simulator.py:120(_step)
      600    0.040    0.000    0.095    0.000 pedped_1d.py:21(b)
      600    0.035    0.000    0.097    0.000 field_of_view.py:18(__call__)
      600    0.035    0.000    0.035    0.000 {built-in method einsum}
     1200    0.034    0.000    0.048    0.000 pedped_1d.py:48(r_ab)
      600    0.030    0.000    0.048    0.000 simulator.py:99(cap_velocity)
       10    0.023    0.002    1.497    0.150 trainer.py:66(epoch)
     1200    0.021    0.000    0.021    0.000 {built-in method torch._C._nn.linear}
     1200    0.017    0.000    0.041    0.000 pedped_1d.py:102(norm_r_ab)
     6000    0.016    0.000    0.016    0.000 {method 'unsqueeze' of 'torch._C._TensorBase' objects}
     8460    0.015    0.000    0.015    0.000 {method 'detach' of 'torch._C._TensorBase' objects}
     1800    0.015    0.000    0.015    0.000 {built-in method clamp}
     3000    0.012    0.000    0.012    0.000 {built-in method diagonal}
      600    0.012    0.000    0.539    0.001 simulator.py:89(f_ab)
      600    0.011    0.000    0.425    0.001 functional.py:194(vjp)
     1200    0.010    0.000    0.010    0.000 {built-in method torch._C._nn.softplus}
 3120/120    0.007    0.000    0.942    0.008 module.py:1045(_call_impl)
 1200/600    0.007    0.000    0.044    0.000 functional.py:186(einsum)
     1200    0.007    0.000    0.007    0.000 {built-in method isnan}
      600    0.007    0.000    0.007    0.000 {built-in method sum}
      600    0.006    0.000    0.439    0.001 pedped_1d.py:89(grad_r_ab_)
      600    0.006    0.000    0.010    0.000 _tensor.py:546(__rdiv__)
     1200    0.006    0.000    0.006    0.000 {method 'view' of 'torch._C._TensorBase' objects}
       60    0.005    0.000    0.936    0.016 simulator.py:110(forward)
      600    0.005    0.000    0.005    0.000 {built-in method ones}
      600    0.005    0.000    0.525    0.001 pedped_1d.py:82(grad_r_ab)
      600    0.005    0.000    0.071    0.000 pedped_1d.py:161(value_b)
      600    0.004    0.000    0.004    0.000 {built-in method sqrt}
     3600    0.004    0.000    0.004    0.000 module.py:1117(__getattr__)
      660    0.004    0.000    0.004    0.000 {method 'clone' of 'torch._C._TensorBase' objects}
      600    0.004    0.000    0.051    0.000 container.py:137(forward)
     1200    0.004    0.000    0.028    0.000 linear.py:95(forward)
      600    0.004    0.000    0.004    0.000 {built-in method full_like}
      600    0.004    0.000    0.011    0.000 stateutils.py:20(speeds)
     1200    0.004    0.000    0.008    0.000 functional.py:43(_grad_preprocess)
      600    0.003    0.000    0.222    0.000 functional.py:127(_autograd_grad)
     1800    0.003    0.000    0.004    0.000 functional.py:7(_as_tuple)
        1    0.003    0.003    1.501    1.501 trainer.py:92(loop)
      600    0.003    0.000    0.003    0.000 {method 'reciprocal' of 'torch._C._TensorBase' objects}
      600    0.003    0.000    0.218    0.000 __init__.py:152(grad)
     3120    0.003    0.000    0.003    0.000 {built-in method torch._C._get_tracing_state}
      600    0.003    0.000    0.003    0.000 {built-in method clone}
       60    0.003    0.000    0.003    0.000 {built-in method torch._C._nn.l1_loss}
    10466    0.003    0.000    0.003    0.000 {built-in method builtins.isinstance}
      660    0.003    0.000    0.003    0.000 __init__.py:28(_make_grads)
      600    0.002    0.000    0.002    0.000 functional.py:150(_fill_in_zeros)
      600    0.002    0.000    0.003    0.000 functional.py:77(_validate_v)
      600    0.002    0.000    0.167    0.000 pedped_1d.py:43(value_r_ab)
     1200    0.002    0.000    0.002    0.000 grad_mode.py:167(__enter__)
      120    0.002    0.000    0.002    0.000 {built-in method torch._ops.profiler._record_function_enter}
     1200    0.002    0.000    0.023    0.000 functional.py:1831(linear)
     1428    0.002    0.000    0.002    0.000 _tensor.py:967(grad)
     1436    0.001    0.000    0.001    0.000 {method 'requires_grad_' of 'torch._C._TensorBase' objects}
     1200    0.001    0.000    0.011    0.000 activation.py:825(forward)
       60    0.001    0.000    0.005    0.000 optimizer.py:188(zero_grad)
       60    0.001    0.000    0.004    0.000 sgd.py:76(step)
      600    0.001    0.000    0.002    0.000 container.py:129(__iter__)
     3720    0.001    0.000    0.001    0.000 {built-in method torch._C._set_grad_enabled}
     1200    0.001    0.000    0.001    0.000 grad_mode.py:171(__exit__)
       60    0.001    0.000    0.009    0.000 optimizer.py:83(wrapper)
      720    0.001    0.000    0.001    0.000 grad_mode.py:213(__init__)
     1320    0.001    0.000    0.001    0.000 {method 'size' of 'torch._C._TensorBase' objects}
      600    0.001    0.000    0.001    0.000 functional.py:95(_check_requires_grad)
      120    0.001    0.000    0.001    0.000 {built-in method zeros}
     4942    0.001    0.000    0.001    0.000 {built-in method builtins.len}
      120    0.001    0.000    0.003    0.000 profiler.py:613(__enter__)
     1200    0.001    0.000    0.001    0.000 functional.py:66(_grad_postprocess)
      240    0.001    0.000    0.001    0.000 {method 'add_' of 'torch._C._TensorBase' objects}
      600    0.001    0.000    0.001    0.000 grad_mode.py:220(__exit__)
      600    0.001    0.000    0.168    0.000 pedped_1d.py:91(compute)
     1980    0.001    0.000    0.001    0.000 {built-in method torch._C.is_grad_enabled}
      660    0.001    0.000    0.001    0.000 _VF.py:25(__getattr__)
     1200    0.001    0.000    0.001    0.000 functional.py:26(_tuple_postprocess)
     2580    0.001    0.000    0.001    0.000 {method 'append' of 'list' objects}
     1860    0.001    0.000    0.001    0.000 {built-in method torch._C._has_torch_function_variadic}
       60    0.000    0.000    0.001    0.000 functional.py:45(broadcast_tensors)
       60    0.000    0.000    0.000    0.000 {built-in method broadcast_tensors}
       60    0.000    0.000    0.005    0.000 functional.py:3031(l1_loss)
      660    0.000    0.000    0.001    0.000 __init__.py:60(_tensor_or_tensors_to_tuple)
     1860    0.000    0.000    0.000    0.000 {built-in method torch._C._has_torch_function}
       60    0.000    0.000    0.000    0.000 {built-in method ones_like}
       60    0.000    0.000    0.518    0.009 __init__.py:68(backward)
       60    0.000    0.000    0.005    0.000 grad_mode.py:25(decorate_context)
       60    0.000    0.000    0.000    0.000 grad_mode.py:119(__init__)
      120    0.000    0.000    0.000    0.000 {built-in method torch._ops.profiler._record_function_exit}
      600    0.000    0.000    0.000    0.000 simulator.py:93(f_aB)
       60    0.000    0.000    0.001    0.000 _functional.py:146(sgd)
       60    0.000    0.000    0.000    0.000 simulator.py:55(normalize_state)
      660    0.000    0.000    0.000    0.000 {built-in method builtins.getattr}
      120    0.000    0.000    0.001    0.000 profiler.py:605(__init__)
       60    0.000    0.000    0.519    0.009 _tensor.py:205(backward)
      600    0.000    0.000    0.000    0.000 {built-in method builtins.iter}
     1488    0.000    0.000    0.000    0.000 {built-in method builtins.hasattr}
     1972    0.000    0.000    0.000    0.000 {built-in method torch._C._has_torch_function_unary}
      484    0.000    0.000    0.000    0.000 _tensor.py:615(__hash__)
      120    0.000    0.000    0.001    0.000 profiler.py:617(__exit__)
      236    0.000    0.000    0.000    0.000 {method 'zero_' of 'torch._C._TensorBase' objects}
      600    0.000    0.000    0.000    0.000 {method 'values' of 'collections.OrderedDict' objects}
       60    0.000    0.000    0.000    0.000 {method 'item' of 'torch._C._TensorBase' objects}
       62    0.000    0.000    0.000    0.000 {method 'format' of 'str' objects}
       60    0.000    0.000    0.005    0.000 loss.py:96(forward)
       60    0.000    0.000    0.000    0.000 grad_mode.py:124(__enter__)
      600    0.000    0.000    0.000    0.000 grad_mode.py:217(__enter__)
       10    0.000    0.000    0.000    0.000 random.py:293(shuffle)
      486    0.000    0.000    0.000    0.000 {built-in method builtins.id}
       60    0.000    0.000    0.000    0.000 grad_mode.py:128(__exit__)
       60    0.000    0.000    0.000    0.000 _reduction.py:7(get_enum)
       50    0.000    0.000    0.000    0.000 random.py:250(_randbelow_with_getrandbits)
        3    0.000    0.000    0.000    0.000 socket.py:480(send)
        2    0.000    0.000    0.000    0.000 {built-in method torch._C._jit_get_operation}
       12    0.000    0.000    0.000    0.000 module.py:1133(__setattr__)
       60    0.000    0.000    0.000    0.000 {method 'numel' of 'torch._C._TensorBase' objects}
       60    0.000    0.000    0.000    0.000 _jit_internal.py:881(is_scripting)
       76    0.000    0.000    0.000    0.000 {method 'getrandbits' of '_random.Random' objects}
        2    0.000    0.000    0.000    0.000 _ops.py:56(__getattr__)
        1    0.000    0.000    0.000    0.000 {built-in method builtins.print}
        3    0.000    0.000    0.000    0.000 iostream.py:206(schedule)
        2    0.000    0.000    0.000    0.000 iostream.py:500(write)
       50    0.000    0.000    0.000    0.000 {method 'bit_length' of 'int' objects}
        1    0.000    0.000    0.000    0.000 module.py:250(__init__)
        3    0.000    0.000    0.000    0.000 threading.py:1071(is_alive)
        1    0.000    0.000    0.000    0.000 trainer.py:17(__init__)
        2    0.000    0.000    0.000    0.000 _builtins.py:160(_register_builtin)
        3    0.000    0.000    0.000    0.000 threading.py:1017(_wait_for_tstate_lock)
        2    0.000    0.000    0.000    0.000 iostream.py:418(_is_master_process)
        1    0.000    0.000    0.000    0.000 _ops.py:52(__init__)
        1    0.000    0.000    0.000    0.000 _ops.py:75(__getattr__)
        3    0.000    0.000    0.000    0.000 iostream.py:96(_event_pipe)
        3    0.000    0.000    0.000    0.000 {method 'acquire' of '_thread.lock' objects}
       36    0.000    0.000    0.000    0.000 {method 'get' of 'dict' objects}
        1    0.000    0.000    0.000    0.000 cProfile.py:133(__exit__)
        2    0.000    0.000    0.000    0.000 {built-in method posix.getpid}
        1    0.000    0.000    0.000    0.000 loss.py:93(__init__)
        1    0.000    0.000    0.000    0.000 loss.py:15(__init__)
        2    0.000    0.000    0.000    0.000 iostream.py:437(_schedule_flush)
        1    0.000    0.000    0.000    0.000 {built-in method torch._C._log_api_usage_once}
        3    0.000    0.000    0.000    0.000 threading.py:513(is_set)
        2    0.000    0.000    0.000    0.000 _builtins.py:129(_get_builtin_table)
        3    0.000    0.000    0.000    0.000 {built-in method builtins.setattr}
        3    0.000    0.000    0.000    0.000 {method 'append' of 'collections.deque' objects}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
<pstats.Stats at 0x7fba29e134f0>
!flameprof simulator.prof > simulator_flame.svg
import IPython
IPython.display.SVG(filename='simulator_flame.svg')
_images/performance_6_0.svg