Skip to content

Commit

Permalink
[Data] [Docs] Prose and formatting updates (Working with Tensors / Wo…
Browse files Browse the repository at this point in the history
…rking with PyTorch pages) (#43992) (#44097)

Cherry-pick #43992. Docs-only change.


Prose and formatting updates for the following docs pages:
- Working with Tensors (renamed to Working with Tensors / NumPy) - [PR version](https://anyscale-ray--43992.com.readthedocs.build/en/43992/data/working-with-tensors.html)
- Working with PyTorch - [PR version](https://anyscale-ray--43992.com.readthedocs.build/en/43992/data/working-with-pytorch.html)

Signed-off-by: Scott Lee <[email protected]>
Co-authored-by: Kevin H. Luu <[email protected]>
  • Loading branch information
scottjlee and khluu authored Mar 18, 2024
1 parent 27b68d1 commit 26295a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions doc/source/data/working-with-pytorch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Iterating over Torch tensors for training
-----------------------------------------
To iterate over batches of data in Torch format, call :meth:`Dataset.iter_torch_batches() <ray.data.Dataset.iter_torch_batches>`. Each batch is represented as `Dict[str, torch.Tensor]`, with one tensor per column in the dataset.

This is useful for training Torch models with batches from your dataset. For configuration details such as providing a ``collate_fn`` for customizing the conversion, see `the API reference <ray.data.Dataset.iter_torch_batches>`.
This is useful for training Torch models with batches from your dataset. For configuration details such as providing a ``collate_fn`` for customizing the conversion, see the API reference for :meth:`iter_torch_batches() <ray.data.Dataset.iter_torch_batches>`.

.. testcode::

Expand Down Expand Up @@ -84,7 +84,7 @@ For more details, see the :ref:`Ray Train user guide <data-ingest-torch>`.

Transformations with Torch tensors
----------------------------------
Transformations applied with `map` or ``map_batches`` can return Torch tensors.
Transformations applied with `map` or `map_batches` can return Torch tensors.

.. caution::

Expand Down Expand Up @@ -159,7 +159,7 @@ For more information on transforming data, see :ref:`Transforming data <transfor
Built-in PyTorch transforms
~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can use built-in Torch transforms from ``torchvision``, ``torchtext``, and ``torchaudio`` Ray Data transformations.
You can use built-in Torch transforms from ``torchvision``, ``torchtext``, and ``torchaudio``.

.. tab-set::

Expand Down Expand Up @@ -273,11 +273,11 @@ With Ray Datasets, you can do scalable offline batch inference with Torch models
# Get the predictions from the input batch.
return {"output": self.model(tensor).numpy()}

# Step 2: Map the Predictor over the Dataset to get predictions.
# Step 3: Map the Predictor over the Dataset to get predictions.
# Use 2 parallel actors for inference. Each actor predicts on a
# different partition of data.
predictions = ds.map_batches(TorchPredictor, concurrency=2)
# Step 3: Show one prediction output.
# Step 4: Show one prediction output.
predictions.show(limit=1)

.. testoutput::
Expand Down Expand Up @@ -469,7 +469,7 @@ PyTorch DataLoader

The PyTorch DataLoader can be replaced by calling :meth:`Dataset.iter_torch_batches() <ray.data.Dataset.iter_torch_batches>` to iterate over batches of the dataset.

The following table describes how the arguments for PyTorch DataLoader map to Ray Data. Note the behavior may not necessarily be identical. For exact semantics and usage, :meth:`see the API reference <ray.data.Dataset.iter_torch_batches>`.
The following table describes how the arguments for PyTorch DataLoader map to Ray Data. Note the behavior may not necessarily be identical. For exact semantics and usage, see the API reference for :meth:`iter_torch_batches() <ray.data.Dataset.iter_torch_batches>`.

.. list-table::
:header-rows: 1
Expand Down
4 changes: 2 additions & 2 deletions doc/source/data/working-with-tensors.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _working_with_tensors:

Working with Tensors
====================
Working with Tensors / NumPy
============================

N-dimensional arrays (in other words, tensors) are ubiquitous in ML workloads. This guide
describes the limitations and best practices of working with such data.
Expand Down

0 comments on commit 26295a5

Please sign in to comment.