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

[Feature] SAC compatibility with compile #2655

Merged
merged 6 commits into from
Dec 16, 2024
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
Update
[ghstack-poisoned]
  • Loading branch information
vmoens committed Dec 16, 2024
commit 0fb954664cdb86f121258a03119010c049683f3e
2 changes: 1 addition & 1 deletion sota-implementations/sac/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ collector:
replay_buffer:
size: 1000000
prb: 0 # use prioritized experience replay
scratch_dir: null
scratch_dir:

# optim
optim:
Expand Down
16 changes: 10 additions & 6 deletions sota-implementations/sac/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from torch import nn, optim
from torchrl.collectors import SyncDataCollector
from torchrl.data import (
LazyMemmapStorage,
LazyTensorStorage,
TensorDictPrioritizedReplayBuffer,
TensorDictReplayBuffer,
Expand Down Expand Up @@ -138,30 +139,33 @@ def make_replay_buffer(
device="cpu",
prefetch=3,
):
storage_cls = (
functools.partial(LazyTensorStorage, device=device)
if not scratch_dir
else functools.partial(LazyMemmapStorage, device="cpu", scratch_dir=scratch_dir)
)
if prb:
replay_buffer = TensorDictPrioritizedReplayBuffer(
alpha=0.7,
beta=0.5,
pin_memory=False,
prefetch=prefetch,
storage=LazyTensorStorage(
storage=storage_cls(
buffer_size,
scratch_dir=scratch_dir,
device=device,
),
batch_size=batch_size,
)
else:
replay_buffer = TensorDictReplayBuffer(
pin_memory=False,
prefetch=prefetch,
storage=LazyTensorStorage(
storage=storage_cls(
buffer_size,
scratch_dir=scratch_dir,
device=device,
),
batch_size=batch_size,
)
if scratch_dir:
replay_buffer.append_transform(lambda td: td.to(device))
return replay_buffer


Expand Down
Loading