Skip to content

Commit 72f8db4

Browse files
authored
Merge branch 'main' into main
2 parents 3dc8ca4 + 80989d2 commit 72f8db4

File tree

9 files changed

+184
-218
lines changed

9 files changed

+184
-218
lines changed

.jenkins/validate_tutorials_built.py

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
"intermediate_source/flask_rest_api_tutorial",
5151
"intermediate_source/text_to_speech_with_torchaudio",
5252
"intermediate_source/tensorboard_profiler_tutorial", # reenable after 2.0 release.
53-
"intermediate_source/torch_export_tutorial", # reenable after 2940 is fixed.
54-
"advanced_source/pendulum",
5553
]
5654

5755
def tutorial_source_dirs() -> List[Path]:

advanced_source/coding_ddpg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ def make_recorder(actor_model_explore, transform_state_dict, record_interval):
893893
record_frames=1000,
894894
policy_exploration=actor_model_explore,
895895
environment=environment,
896-
exploration_type=ExplorationType.MEAN,
896+
exploration_type=ExplorationType.DETERMINISTIC,
897897
record_interval=record_interval,
898898
)
899899
return recorder_obj

advanced_source/pendulum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ def __init__(self, td_params=None, seed=None, device="cpu"):
604604
env,
605605
# ``Unsqueeze`` the observations that we will concatenate
606606
UnsqueezeTransform(
607-
unsqueeze_dim=-1,
607+
dim=-1,
608608
in_keys=["th", "thdot"],
609609
in_keys_inv=["th", "thdot"],
610610
),

beginner_source/examples_autograd/polynomial_autograd.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
import torch
1818
import math
1919

20+
# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`__
21+
# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.
22+
2023
dtype = torch.float
21-
device = "cuda" if torch.cuda.is_available() else "cpu"
24+
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu"
25+
print(f"Using {device} device")
2226
torch.set_default_device(device)
2327

2428
# Create Tensors to hold input and outputs.

beginner_source/fgsm_tutorial.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,9 @@
125125
# `pytorch/examples/mnist <https://github.com/pytorch/examples/tree/master/mnist>`__.
126126
# For simplicity, download the pretrained model `here <https://drive.google.com/file/d/1HJV2nUHJqclXQ8flKvcWmjZ-OU5DGatl/view?usp=drive_link>`__.
127127
#
128-
# - ``use_cuda`` - boolean flag to use CUDA if desired and available.
129-
# Note, a GPU with CUDA is not critical for this tutorial as a CPU will
130-
# not take much time.
131-
#
132128

133129
epsilons = [0, .05, .1, .15, .2, .25, .3]
134130
pretrained_model = "data/lenet_mnist_model.pth"
135-
use_cuda=True
136131
# Set random seed for reproducibility
137132
torch.manual_seed(42)
138133

@@ -184,9 +179,10 @@ def forward(self, x):
184179
])),
185180
batch_size=1, shuffle=True)
186181

187-
# Define what device we are using
188-
print("CUDA Available: ",torch.cuda.is_available())
189-
device = torch.device("cuda" if use_cuda and torch.cuda.is_available() else "cpu")
182+
# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`__
183+
# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.
184+
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu"
185+
print(f"Using {device} device")
190186

191187
# Initialize the network
192188
model = Net().to(device)

beginner_source/transfer_learning_tutorial.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@
9898
dataset_sizes = {x: len(image_datasets[x]) for x in ['train', 'val']}
9999
class_names = image_datasets['train'].classes
100100

101-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
101+
# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`__
102+
# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.
103+
104+
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu"
105+
print(f"Using {device} device")
102106

103107
######################################################################
104108
# Visualize a few images

intermediate_source/dqn_with_rnn_tutorial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@
433433
exploration_module.step(data.numel())
434434
updater.step()
435435

436-
with set_exploration_type(ExplorationType.MODE), torch.no_grad():
436+
with set_exploration_type(ExplorationType.DETERMINISTIC), torch.no_grad():
437437
rollout = env.rollout(10000, stoch_policy)
438438
traj_lens.append(rollout.get(("next", "step_count")).max().item())
439439

intermediate_source/reinforcement_ppo.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@
419419
in_keys=["loc", "scale"],
420420
distribution_class=TanhNormal,
421421
distribution_kwargs={
422-
"min": env.action_spec.space.low,
423-
"max": env.action_spec.space.high,
422+
"low": env.action_spec.space.low,
423+
"high": env.action_spec.space.high,
424424
},
425425
return_log_prob=True,
426426
# we'll need the log-prob for the numerator of the importance weights

0 commit comments

Comments
 (0)