# Memory mapped Tensor?

**URL:** <https://discuss.pytorch.org/t/memory-mapped-tensor/8954>\
**Category:** Uncategorized\
**Created:** [October 22, 2017, 11:34pm UTC](https://discuss.pytorch.org/t/memory-mapped-tensor/8954 "2017-10-22T23:34:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbp28](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mbp28/32/4265_2.png) [@mbp28](https://discuss.pytorch.org/u/mbp28)\
**Post date:** [October 22, 2017, 11:34pm UTC](https://discuss.pytorch.org/t/memory-mapped-tensor/8954/1 "2017-10-22T23:34:51Z")

</div>

Hello,

I was wondering whether something like `numpy.memmap` exists in PyTorch? Or should I just save as a numpy array and use `numpy.memmap` instead, because conversion to torch tensors is cheap?

Numpy: [https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.memmap.html](https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.memmap.html)

---

<div class="post-metadata">

**Author:** ![colesbury](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/colesbury/32/26_2.png) [@colesbury](https://discuss.pytorch.org/u/colesbury)\
**Post date:** [October 22, 2017, 11:46pm UTC](https://discuss.pytorch.org/t/memory-mapped-tensor/8954/2 "2017-10-22T23:46:46Z")

</div>

You can use `torch.Storage.from_file` ([docs](http://pytorch.org/docs/master/storage.html?highlight=from_file#torch.FloatStorage.from_file)):

e.g.

```python
x = torch.IntTensor(torch.IntStorage.from_file('file.bin', size=100))
```

---

<div class="post-metadata">

**Author:** ![Santosh-Gupta](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/santosh-gupta/32/30716_2.png) [@Santosh-Gupta](https://discuss.pytorch.org/u/Santosh-Gupta)\
**Post date:** [August 12, 2019, 7:39pm UTC](https://discuss.pytorch.org/t/memory-mapped-tensor/8954/3 "2019-08-12T19:39:50Z")

</div>

Is there a way to store the data to memory mapped files as well. Does Pytorch have a method for this?

---

<div class="post-metadata">

**Author:** ![vmoens](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/vmoens/32/26121_2.png) [@vmoens](https://discuss.pytorch.org/u/vmoens)\
**Post date:** [October 6, 2022, 8:49am UTC](https://discuss.pytorch.org/t/memory-mapped-tensor/8954/4 "2022-10-06T08:49:39Z")

</div>

Check this feature from TorchRL if you’re interested in it:

> <https://github.com/pytorch/rl/blob/main/torchrl/data/tensordict/memmap.py>
