Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs][train]Make Train example titles, heading more consistent #39606

Merged
merged 18 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Reverting changes to docstrings

Signed-off-by: angelinalg <[email protected]>
  • Loading branch information
angelinalg committed Sep 13, 2023
commit 0d35ba9037b2b8fa4f8871597dea03cc4c680783
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def train_func(config):
"""Your training function that is launched on each worker."""
"""Your training function that will be launched on each worker."""

# Unpack training configs
lr = config["lr"]
Expand Down Expand Up @@ -116,7 +116,7 @@ def collate_fn(batch):
eval_metric = metric.compute()
accelerator.print(f"epoch {epoch}:", eval_metric)

# Report checkpoint and metrics to Ray Train
# Report Checkpoint and metrics to Ray Train
# ==========================================
with TemporaryDirectory() as tmpdir:
if accelerator.is_main_process:
Expand Down
14 changes: 7 additions & 7 deletions python/ray/train/examples/pytorch/torch_fashion_mnist_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ def get_dataloaders(batch_size):
transform = transforms.Compose([ToTensor(), Normalize((0.5,), (0.5,))])

with FileLock(os.path.expanduser("~/data.lock")):
# Download training data from open datasets
# Download training data from open datasets.
training_data = datasets.FashionMNIST(
root="~/data",
train=True,
download=True,
transform=transform,
)

# Download test data from open datasets
# Download test data from open datasets.
test_data = datasets.FashionMNIST(
root="~/data",
train=False,
download=True,
transform=transform,
)

# Create data loaders
# Create data loaders.
train_dataloader = DataLoader(training_data, batch_size=batch_size)
test_dataloader = DataLoader(test_data, batch_size=batch_size)

Expand Down Expand Up @@ -69,7 +69,7 @@ def train_func_per_worker(config: Dict):
epochs = config["epochs"]
batch_size = config["batch_size_per_worker"]

# Get dataloaders inside the worker training function
# Get dataloaders inside worker training function
train_dataloader, test_dataloader = get_dataloaders(batch_size=batch_size)

# [1] Prepare Dataloader for distributed training
Expand All @@ -81,7 +81,7 @@ def train_func_per_worker(config: Dict):
model = NeuralNetwork()

# [2] Prepare and wrap your model with DistributedDataParallel
# Move the model to the correct GPU/CPU device
# Move the model the correct GPU/CPU device
# ============================================================
model = ray.train.torch.prepare_model(model)

Expand Down Expand Up @@ -137,9 +137,9 @@ def train_fashion_mnist(num_workers=2, use_gpu=False):
scaling_config=scaling_config,
)

# [4] Start distributed training
# [4] Start Distributed Training
# Run `train_func_per_worker` on all workers
# ==========================================
# =============================================
result = trainer.fit()
print(f"Training result: {result}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from ray.train.torch import TorchTrainer


# [1] Define a training function that includes all your training logic
# ====================================================================
# [1] Define a training function that includes all your training logics
# =====================================================================
def train_func(config):
# Datasets
dataset = load_dataset("yelp_review_full")
Expand All @@ -34,15 +34,15 @@ def tokenize_function(examples):
"bert-base-cased", num_labels=5
)

# Evaluation metrics
# Evaluation Metrics
metric = evaluate.load("accuracy")

def compute_metrics(eval_pred):
logits, labels = eval_pred
predictions = np.argmax(logits, axis=-1)
return metric.compute(predictions=predictions, references=labels)

# Hugging Face Trainer
# HuggingFace Trainer
training_args = TrainingArguments(
output_dir="test_trainer", evaluation_strategy="epoch", report_to="none"
)
Expand All @@ -59,7 +59,7 @@ def compute_metrics(eval_pred):
# ===============================================
trainer.add_callback(RayTrainReportCallback())

# [3] Prepare your trainer for Ray Data integration
# [3] Prepare your trainer for Ray Data Integration
# =================================================
trainer = prepare_trainer(trainer)

Expand Down
4 changes: 1 addition & 3 deletions python/ray/train/torch/torch_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class TorchTrainer(DataParallelTrainer):
4. Runs the input ``train_loop_per_worker(train_loop_config)``
on all workers.

For more details, see :ref:`PyTorch Guide <train-pytorch>`,
:ref:`PyTorch Lightning Guide <train-pytorch-lightning>`,
or :ref:`Hugging Face Transformers Guide <train-pytorch-transformers>`.
For more details, see the :ref:`PyTorch User Guide <train-pytorch>`.

Example:

Expand Down
Loading