# tensorplay.functional.from_file Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.from_file.html ```python tensorplay.functional.from_file(filename, shared=None, size=0, *, dtype=None, layout=None, device=None, pin_memory=False) ``` Creates a CPU tensor with a storage backed by a memory-mapped file. If shared is True, then memory is shared between processes. All changes are written to the file. If shared is False, then changes to the tensor do not affect the file. size is the number of elements in the Tensor. If shared is False, then the file must contain at least size * sizeof(dtype) bytes. If shared is True the file will be created if needed. > **Note** > > Only CPU tensors can be mapped to files. > **Note** > > For now, tensors with storages backed by a memory-mapped file cannot be created in pinned memory. Parameters: - filename ([str](https://docs.python.org/3/builtins/stdtypes.html#str)) – file name to map - shared ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – whether to share memory (whether MAP_SHARED or MAP_PRIVATE is passed to the underlying [mmap(2) call](https://man7.org/linux/man-pages/man2/mmap.2.html)) - size ([int](https://docs.python.org/3/builtins/functions.html#int)) – number of elements in the tensor Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). - layout (tensorplay.layout, optional) – the desired layout of returned Tensor. Default: tensorplay.strided. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. Example: ``` >>> t = tensorplay.randn(2, 5, dtype=tensorplay.float64) >>> t.numpy().tofile('storage.pt') >>> t_mapped = tensorplay.from_file('storage.pt', shared=False, size=10, dtype=tensorplay.float64) ```