Skip to content

Commit 592d369

Browse files
authored
Merge branch 'main' into improve-quantization-recipe
2 parents 610ff23 + 7e83c23 commit 592d369

File tree

8 files changed

+49
-25
lines changed

8 files changed

+49
-25
lines changed

.jenkins/validate_tutorials_built.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"intermediate_source/_torch_export_nightly_tutorial", # does not work on release
2929
"advanced_source/super_resolution_with_onnxruntime",
3030
"advanced_source/ddp_pipeline", # requires 4 gpus
31-
"advanced_source/usb_semisup_learn", # in the current form takes 140+ minutes to build - can be enabled when the build time is reduced
3231
"prototype_source/fx_graph_mode_ptq_dynamic",
3332
"prototype_source/vmap_recipe",
3433
"prototype_source/torchscript_freezing",

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ GALLERY_PATTERN="neural_style_transfer_tutorial.py" sphinx-build . _build
5757

5858
The `GALLERY_PATTERN` variable respects regular expressions.
5959

60+
6061
## About contributing to PyTorch Documentation and Tutorials
6162
* You can find information about contributing to PyTorch documentation in the
6263
PyTorch Repo [README.md](https://github.com/pytorch/pytorch/blob/master/README.md) file.
6364
* Additional information can be found in [PyTorch CONTRIBUTING.md](https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md).
65+
66+
67+
## License
68+
69+
PyTorch Tutorials is BSD licensed, as found in the LICENSE file.
555 KB
Loading

advanced_source/usb_semisup_learn.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
**Author**: `Hao Chen <https://github.com/Hhhhhhao>`_
66
77
Unified Semi-supervised learning Benchmark (USB) is a semi-supervised
8-
learning framework built upon PyTorch.
8+
learning (SSL) framework built upon PyTorch.
99
Based on Datasets and Modules provided by PyTorch, USB becomes a flexible,
1010
modular, and easy-to-use framework for semi-supervised learning.
1111
It supports a variety of semi-supervised learning algorithms, including
@@ -17,7 +17,7 @@
1717
This tutorial will walk you through the basics of using the USB lighting
1818
package.
1919
Let's get started by training a ``FreeMatch``/``SoftMatch`` model on
20-
CIFAR-10 using pretrained ViT!
20+
CIFAR-10 using pretrained Vision Transformers (ViT)!
2121
And we will show it is easy to change the semi-supervised algorithm and train
2222
on imbalanced datasets.
2323
@@ -64,6 +64,9 @@
6464
# Now, let's use USB to train ``FreeMatch`` and ``SoftMatch`` on CIFAR-10.
6565
# First, we need to install USB package ``semilearn`` and import necessary API
6666
# functions from USB.
67+
# If you are running this in Google Colab, install ``semilearn`` by running:
68+
# ``!pip install semilearn``.
69+
#
6770
# Below is a list of functions we will use from ``semilearn``:
6871
#
6972
# - ``get_dataset`` to load dataset, here we use CIFAR-10
@@ -77,6 +80,10 @@
7780
# - ``Trainer``: a Trainer class for training and evaluating the
7881
# algorithm on dataset
7982
#
83+
# Note that a CUDA-enabled backend is required for training with the ``semilearn`` package.
84+
# See `Enabling CUDA in Google Colab <https://pytorch.org/tutorials/beginner/colab#using-cuda>`__ for instructions
85+
# on enabling CUDA in Google Colab.
86+
#
8087
import semilearn
8188
from semilearn import get_dataset, get_data_loader, get_net_builder, get_algorithm, get_config, Trainer
8289

@@ -92,7 +99,7 @@
9299

93100
# optimization configs
94101
'epoch': 1,
95-
'num_train_iter': 4000,
102+
'num_train_iter': 500,
96103
'num_eval_iter': 500,
97104
'num_log_iter': 50,
98105
'optim': 'AdamW',
@@ -141,16 +148,16 @@
141148

142149
######################################################################
143150
# We can start training the algorithms on CIFAR-10 with 40 labels now.
144-
# We train for 4000 iterations and evaluate every 500 iterations.
151+
# We train for 500 iterations and evaluate every 500 iterations.
145152
#
146153
trainer = Trainer(config, algorithm)
147154
trainer.fit(train_lb_loader, train_ulb_loader, eval_loader)
148155

149156

150157
######################################################################
151158
# Finally, let's evaluate the trained model on the validation set.
152-
# After training 4000 iterations with ``FreeMatch`` on only 40 labels of
153-
# CIFAR-10, we obtain a classifier that achieves above 93 accuracy on the validation set.
159+
# After training 500 iterations with ``FreeMatch`` on only 40 labels of
160+
# CIFAR-10, we obtain a classifier that achieves around 87% accuracy on the validation set.
154161
trainer.evaluate(eval_loader)
155162

156163

@@ -174,7 +181,7 @@
174181

175182
# optimization configs
176183
'epoch': 1,
177-
'num_train_iter': 4000,
184+
'num_train_iter': 500,
178185
'num_eval_iter': 500,
179186
'num_log_iter': 50,
180187
'optim': 'AdamW',
@@ -225,7 +232,7 @@
225232

226233
######################################################################
227234
# We can start Train the algorithms on CIFAR-10 with 40 labels now.
228-
# We train for 4000 iterations and evaluate every 500 iterations.
235+
# We train for 500 iterations and evaluate every 500 iterations.
229236
#
230237
trainer = Trainer(config, algorithm)
231238
trainer.fit(train_lb_loader, train_ulb_loader, eval_loader)
@@ -239,8 +246,8 @@
239246

240247

241248
######################################################################
242-
# References
243-
# [1] USB: https://github.com/microsoft/Semi-supervised-learning
244-
# [2] Kihyuk Sohn et al. FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence
245-
# [3] Yidong Wang et al. FreeMatch: Self-adaptive Thresholding for Semi-supervised Learning
246-
# [4] Hao Chen et al. SoftMatch: Addressing the Quantity-Quality Trade-off in Semi-supervised Learning
249+
# References:
250+
# - [1] USB: https://github.com/microsoft/Semi-supervised-learning
251+
# - [2] Kihyuk Sohn et al. FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence
252+
# - [3] Yidong Wang et al. FreeMatch: Self-adaptive Thresholding for Semi-supervised Learning
253+
# - [4] Hao Chen et al. SoftMatch: Addressing the Quantity-Quality Trade-off in Semi-supervised Learning

beginner_source/colab.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,11 @@ Hopefully this example will give you a good starting point for running
9393
some of the more complex tutorials in Colab. As we evolve our use of
9494
Colab on the PyTorch tutorials site, we'll look at ways to make this
9595
easier for users.
96+
97+
Enabling CUDA
98+
~~~~~~~~~~~~~~~~
99+
Some tutorials require a CUDA-enabled device (NVIDIA GPU), which involves
100+
changing the Runtime type prior to executing the tutorial.
101+
To change the Runtime in Google Colab, on the top drop-down menu select **Runtime**,
102+
then select **Change runtime type**. Under **Hardware accelerator**, select ``T4 GPU``,
103+
then click ``Save``.

beginner_source/hyperparameter_tuning_tutorial.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,21 @@
4848
from torch.utils.data import random_split
4949
import torchvision
5050
import torchvision.transforms as transforms
51+
# sphinx_gallery_start_ignore
52+
# Fixes ``AttributeError: '_LoggingTee' object has no attribute 'fileno'``.
53+
# This is only needed to run with sphinx-build.
54+
import sys
55+
if not hasattr(sys.stdout, "encoding"):
56+
sys.stdout.encoding = "latin1"
57+
sys.stdout.fileno = lambda: 0
58+
# sphinx_gallery_end_ignore
5159
from ray import tune
5260
from ray.air import Checkpoint, session
5361
from ray.tune.schedulers import ASHAScheduler
5462

63+
# TODO: Migrate to ray.train.Checkpoint and remove following line
64+
os.environ["RAY_AIR_NEW_PERSISTENCE_MODE"]="0"
65+
5566
######################################################################
5667
# Most of the imports are needed for building the PyTorch model. Only the last three
5768
# imports are for Ray Tune.
@@ -448,13 +459,6 @@ def main(num_samples=10, max_num_epochs=10, gpus_per_trial=2):
448459

449460

450461
if __name__ == "__main__":
451-
# sphinx_gallery_start_ignore
452-
# Fixes ``AttributeError: '_LoggingTee' object has no attribute 'fileno'``.
453-
# This is only needed to run with sphinx-build.
454-
import sys
455-
456-
sys.stdout.fileno = lambda: False
457-
# sphinx_gallery_end_ignore
458462
# You can change the number of GPUs per trial here:
459463
main(num_samples=10, max_num_epochs=10, gpus_per_trial=0)
460464

recipes_source/distributed_device_mesh.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Prerequisites:
1414

1515

1616
Setting up distributed communicators, i.e. NVIDIA Collective Communication Library (NCCL) communicators, for distributed training can pose a significant challenge. For workloads where users need to compose different parallelisms,
17-
users would need to manually set up and manage NCCL communicators (for example, :class:`ProcessGroup`) for each parallelism solutions. This process could be complicated and susceptible to errors.
17+
users would need to manually set up and manage NCCL communicators (for example, :class:`ProcessGroup`) for each parallelism solution. This process could be complicated and susceptible to errors.
1818
:class:`DeviceMesh` can simplify this process, making it more manageable and less prone to errors.
1919

2020
What is DeviceMesh
@@ -30,7 +30,7 @@ Users can also easily manage the underlying process_groups/devices for multi-dim
3030

3131
Why DeviceMesh is Useful
3232
------------------------
33-
DeviceMesh is useful when working with multi-dimensional parallelism (i.e. 3-D parallel) where parallelism composability is requried. For example, when your parallelism solutions require both communication across hosts and within each host.
33+
DeviceMesh is useful when working with multi-dimensional parallelism (i.e. 3-D parallel) where parallelism composability is required. For example, when your parallelism solutions require both communication across hosts and within each host.
3434
The image above shows that we can create a 2D mesh that connects the devices within each host, and connects each device with its counterpart on the other hosts in a homogenous setup.
3535

3636
Without DeviceMesh, users would need to manually set up NCCL communicators, cuda devices on each process before applying any parallelism, which could be quite complicated.
@@ -95,7 +95,7 @@ access the underlying :class:`ProcessGroup` if needed.
9595
from torch.distributed.device_mesh import init_device_mesh
9696
mesh_2d = init_device_mesh("cuda", (2, 4), mesh_dim_names=("replicate", "shard"))
9797
98-
# Users can acess the undelying process group thru `get_group` API.
98+
# Users can access the underlying process group thru `get_group` API.
9999
replicate_group = mesh_2d.get_group(mesh_dim="replicate")
100100
shard_group = mesh_2d.get_group(mesh_dim="shard")
101101

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bs4
2020
awscliv2==2.1.1
2121
flask
2222
spacy==3.4.1
23-
ray[tune]==2.4.0
23+
ray[tune]==2.7.2
2424
tensorboard
2525
jinja2==3.1.3
2626
pytorch-lightning

0 commit comments

Comments
 (0)