0

When using mxnet, after building and training a module mod, I called the method mod.get_params() to inspect the weights and bias of the model.

However, I found that even if I set the context to mx.gpu(0) when creating the module, the outputs of the get_params method always show that the parameters (weights and bias) are on cpu(0). See below:

results of get_params

I wonder whether the weights were really on cpu, so I timed the program and found that, it was in fact much faster if I set the context to gpu(0) than to cpu(0). Therefore, I think the weights were in fact on gpu, otherwise the training wouldn't be so fast. But, why did the get_params method show that my weights were on cpu?

Mika Sundland
  • 18,120
  • 16
  • 38
  • 50
Runze Mao
  • 1
  • 1

1 Answers1

0

Calling mod.get_params synchronizes the parameters in GPU memory, with a copy that is placed in CPU memory. You're seeing the copy, that's in the cpu context, so there's no need for concern.

Under the hood, _sync_params_from_devices is called if the parameters are 'dirty' (i.e. out of sync); where 'device' is GPU(s).

Thom Lane
  • 993
  • 9
  • 9