[null,null,["Last updated 2023-03-17 UTC."],[],[],null,["# tf.data.experimental.prefetch_to_device\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.9.3/tensorflow/python/data/experimental/ops/prefetching_ops.py#L33-L62) |\n\nA transformation that prefetches dataset values to the given `device`.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.data.experimental.prefetch_to_device`](https://www.tensorflow.org/api_docs/python/tf/data/experimental/prefetch_to_device)\n\n\u003cbr /\u003e\n\n tf.data.experimental.prefetch_to_device(\n device, buffer_size=None\n )\n\n| **Note:** Although the transformation creates a [`tf.data.Dataset`](../../../tf/data/Dataset), the transformation must be the final `Dataset` in the input pipeline.\n\nFor example, \n\n \u003e\u003e\u003e dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3])\n \u003e\u003e\u003e dataset = dataset.apply(tf.data.experimental.prefetch_to_device(\"/cpu:0\"))\n \u003e\u003e\u003e for element in dataset:\n ... print(f'Tensor {element} is on device {element.device}')\n Tensor 1 is on device /job:localhost/replica:0/task:0/device:CPU:0\n Tensor 2 is on device /job:localhost/replica:0/task:0/device:CPU:0\n Tensor 3 is on device /job:localhost/replica:0/task:0/device:CPU:0\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|------------------------------------------------------------------------------------------------------|\n| `device` | A string. The name of a device to which elements will be prefetched. |\n| `buffer_size` | (Optional.) The number of elements to buffer on `device`. Defaults to an automatically chosen value. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Dataset` transformation function, which can be passed to [`tf.data.Dataset.apply`](../../../tf/data/Dataset#apply). ||\n\n\u003cbr /\u003e"]]