# \`torch.load\` does not map to GPU as advertised

**URL:** <https://discuss.pytorch.org/t/torch-load-does-not-map-to-gpu-as-advertised/74637>\
**Category:** Uncategorized\
**Created:** [March 28, 2020, 9:57pm UTC](https://discuss.pytorch.org/t/torch-load-does-not-map-to-gpu-as-advertised/74637 "2020-03-28T21:57:11Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![murph213](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@murph213](https://discuss.pytorch.org/u/murph213)\
**Post date:** [March 31, 2020, 12:02pm UTC](https://discuss.pytorch.org/t/torch-load-does-not-map-to-gpu-as-advertised/74637/4 "2020-03-31T12:02:11Z")

</div>

I have made some progress on this issue, by using on `torch.cuda.memory_summary` rather than `mytensor.device`. It turns out that using `map_location` with options that specify the GPU _reserves_ GPU memory but then stores the model.device as “cpu”. In particular, it seems that memory is stored on the GPU and then immediately freed. However, when you use the default `map_location`, it does not reserve GPU memory at all, GPU memory is never allocated and thus never freed (at least until you call `mytensor.to()`).

By tracking process CPU memory with `psutil`, I found that using `map_location` to GPU causes the total CPU process memory to spike immediately after calling `torch.load`. However, if you use the `map_location` default, the total CPU memory does not increase until after you call `mytensor.to()`. In particular, both approaches (with/without `map_location` and then `to()`) end up using about the same process CPU memory, but using `map_location` to GPU gets to that high number after `torch.load` but `map_location` to CPU doesn’t get there until after `.to`.

I’m left wondering whether this was intended behavior.

---

_[View the full topic](https://discuss.pytorch.org/t/torch-load-does-not-map-to-gpu-as-advertised/74637)._
