Skip to content

[Feature] Collector.fake_tensordict() / MultiCollector.fake_tensordict()#3764

Merged
vmoens merged 7 commits into
gh/vmoens/280/basefrom
gh/vmoens/280/head
May 18, 2026
Merged

[Feature] Collector.fake_tensordict() / MultiCollector.fake_tensordict()#3764
vmoens merged 7 commits into
gh/vmoens/280/basefrom
gh/vmoens/280/head

Conversation

@vmoens
Copy link
Copy Markdown
Collaborator

@vmoens vmoens commented May 15, 2026

Stack from ghstack (oldest at bottom):

Public method that returns a zero-filled tensordict shaped exactly like
one batch yielded by the collector, useful for storage initialization
and torch.compile / cudagraph warmup without having to step the env
first.

Collector.fake_tensordict() (single-process):

  • Reuses the existing _final_rollout template; builds it lazily via
    _maybe_make_final_rollout(make_rollout=True) even when
    use_buffers=False so the public API is consistent.
  • Mirrors the rollout post-pipeline: _maybe_attach_final_obs,
    _maybe_set_truncated, then _postproc (which runs
    split_trajectories, the user postproc, and private-key
    exclusion).
  • Result: env keys + policy out-keys + ("collector", "traj_ids"),
    compact_obs exclusions and final_obs UnbatchedTensor
    leaves applied, last dim named "time".

MultiCollector.fake_tensordict() raises NotImplementedError.
Honoring the contract on the parent process would either require
creating an env there (which defeats the purpose of a multi-process
collector — Isaac Lab / mujoco-mjx etc. can only run in workers) or
routing a request to a worker over the pipe (which requires live
workers and adds protocol surface). Neither is in scope here; users
who need a fake tensordict can call it on a single-process
:class:~torchrl.collectors.Collector.

Tests pin: shape / names / keys / zero-fill parity between
fake_tensordict() and next(iter(collector)) (with and without
buffers); compact_obs drops ("next", obs) and final_obs
attaches ("final", obs) as UnbatchedTensor; and that
MultiCollector.fake_tensordict() raises NotImplementedError.

[ghstack-poisoned]
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 15, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3764

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 3 New Failures, 1 Cancelled Job

As of commit 7ef328e with merge base 0a01ee8 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOB - The following job was cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 15, 2026
vmoens added a commit that referenced this pull request May 15, 2026
Public method that returns a zero-filled tensordict shaped exactly like
one batch yielded by the collector, useful for storage initialization
and ``torch.compile`` / cudagraph warmup without having to step the env
first.

``Collector.fake_tensordict()`` (single-process):

- Reuses the existing ``_final_rollout`` template; builds it lazily via
  ``_maybe_make_final_rollout(make_rollout=True)`` even when
  ``use_buffers=False`` so the public API is consistent.
- Mirrors the rollout post-pipeline: ``_maybe_attach_final_obs``,
  ``_maybe_set_truncated``, then ``_postproc`` (which runs
  ``split_trajectories``, the user ``postproc``, and private-key
  exclusion).
- Result: env keys + policy out-keys + ``("collector", "traj_ids")``,
  ``compact_obs`` exclusions and ``final_obs`` ``UnbatchedTensor``
  leaves applied, last dim named ``"time"``.

``MultiCollector.fake_tensordict()`` raises ``NotImplementedError``.
Honoring the contract on the parent process would either require
creating an env there (which defeats the purpose of a multi-process
collector — Isaac Lab / mujoco-mjx etc. can only run in workers) or
routing a request to a worker over the pipe (which requires live
workers and adds protocol surface). Neither is in scope here; users
who need a fake tensordict can call it on a single-process
:class:`~torchrl.collectors.Collector`.

Tests pin: shape / names / keys / zero-fill parity between
``fake_tensordict()`` and ``next(iter(collector))`` (with and without
buffers); ``compact_obs`` drops ``("next", obs)`` and ``final_obs``
attaches ``("final", obs)`` as ``UnbatchedTensor``; and that
``MultiCollector.fake_tensordict()`` raises ``NotImplementedError``.


ghstack-source-id: c2b5dbb
Pull-Request: #3764
[ghstack-poisoned]
vmoens added a commit that referenced this pull request May 15, 2026
Public method that returns a zero-filled tensordict shaped exactly like
one batch yielded by the collector, useful for storage initialization
and ``torch.compile`` / cudagraph warmup without having to step the env
first.

``Collector.fake_tensordict()`` (single-process):

- Reuses the existing ``_final_rollout`` template; builds it lazily via
  ``_maybe_make_final_rollout(make_rollout=True)`` even when
  ``use_buffers=False`` so the public API is consistent.
- Mirrors the rollout post-pipeline: ``_maybe_attach_final_obs``,
  ``_maybe_set_truncated``, then ``_postproc`` (which runs
  ``split_trajectories``, the user ``postproc``, and private-key
  exclusion).
- Result: env keys + policy out-keys + ``("collector", "traj_ids")``,
  ``compact_obs`` exclusions and ``final_obs`` ``UnbatchedTensor``
  leaves applied, last dim named ``"time"``.

``MultiCollector.fake_tensordict()`` raises ``NotImplementedError``.
Honoring the contract on the parent process would either require
creating an env there (which defeats the purpose of a multi-process
collector — Isaac Lab / mujoco-mjx etc. can only run in workers) or
routing a request to a worker over the pipe (which requires live
workers and adds protocol surface). Neither is in scope here; users
who need a fake tensordict can call it on a single-process
:class:`~torchrl.collectors.Collector`.

Tests pin: shape / names / keys / zero-fill parity between
``fake_tensordict()`` and ``next(iter(collector))`` (with and without
buffers); ``compact_obs`` drops ``("next", obs)`` and ``final_obs``
attaches ``("final", obs)`` as ``UnbatchedTensor``; and that
``MultiCollector.fake_tensordict()`` raises ``NotImplementedError``.


ghstack-source-id: 38de918
Pull-Request: #3764
[ghstack-poisoned]
vmoens added a commit that referenced this pull request May 15, 2026
Public method that returns a zero-filled tensordict shaped exactly like
one batch yielded by the collector, useful for storage initialization
and ``torch.compile`` / cudagraph warmup without having to step the env
first.

``Collector.fake_tensordict()`` (single-process):

- Reuses the existing ``_final_rollout`` template; builds it lazily via
  ``_maybe_make_final_rollout(make_rollout=True)`` even when
  ``use_buffers=False`` so the public API is consistent.
- Mirrors the rollout post-pipeline: ``_maybe_attach_final_obs``,
  ``_maybe_set_truncated``, then ``_postproc`` (which runs
  ``split_trajectories``, the user ``postproc``, and private-key
  exclusion).
- Result: env keys + policy out-keys + ``("collector", "traj_ids")``,
  ``compact_obs`` exclusions and ``final_obs`` ``UnbatchedTensor``
  leaves applied, last dim named ``"time"``.

``MultiCollector.fake_tensordict()`` raises ``NotImplementedError``.
Honoring the contract on the parent process would either require
creating an env there (which defeats the purpose of a multi-process
collector — Isaac Lab / mujoco-mjx etc. can only run in workers) or
routing a request to a worker over the pipe (which requires live
workers and adds protocol surface). Neither is in scope here; users
who need a fake tensordict can call it on a single-process
:class:`~torchrl.collectors.Collector`.

Tests pin: shape / names / keys / zero-fill parity between
``fake_tensordict()`` and ``next(iter(collector))`` (with and without
buffers); ``compact_obs`` drops ``("next", obs)`` and ``final_obs``
attaches ``("final", obs)`` as ``UnbatchedTensor``; and that
``MultiCollector.fake_tensordict()`` raises ``NotImplementedError``.


ghstack-source-id: f46dbe7
Pull-Request: #3764
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
vmoens added a commit that referenced this pull request May 18, 2026
Public method that returns a zero-filled tensordict shaped exactly like
one batch yielded by the collector, useful for storage initialization
and ``torch.compile`` / cudagraph warmup without having to step the env
first.

``Collector.fake_tensordict()`` (single-process):

- Reuses the existing ``_final_rollout`` template; builds it lazily via
  ``_maybe_make_final_rollout(make_rollout=True)`` even when
  ``use_buffers=False`` so the public API is consistent.
- Mirrors the rollout post-pipeline: ``_maybe_attach_final_obs``,
  ``_maybe_set_truncated``, then ``_postproc`` (which runs
  ``split_trajectories``, the user ``postproc``, and private-key
  exclusion).
- Result: env keys + policy out-keys + ``("collector", "traj_ids")``,
  ``compact_obs`` exclusions and ``final_obs`` ``UnbatchedTensor``
  leaves applied, last dim named ``"time"``.

``MultiCollector.fake_tensordict()`` raises ``NotImplementedError``.
Honoring the contract on the parent process would either require
creating an env there (which defeats the purpose of a multi-process
collector — Isaac Lab / mujoco-mjx etc. can only run in workers) or
routing a request to a worker over the pipe (which requires live
workers and adds protocol surface). Neither is in scope here; users
who need a fake tensordict can call it on a single-process
:class:`~torchrl.collectors.Collector`.

Tests pin: shape / names / keys / zero-fill parity between
``fake_tensordict()`` and ``next(iter(collector))`` (with and without
buffers); ``compact_obs`` drops ``("next", obs)`` and ``final_obs``
attaches ``("final", obs)`` as ``UnbatchedTensor``; and that
``MultiCollector.fake_tensordict()`` raises ``NotImplementedError``.

ghstack-source-id: 6db6382
Pull-Request: #3764
@vmoens vmoens merged commit 7ef328e into gh/vmoens/280/base May 18, 2026
107 of 113 checks passed
@vmoens vmoens deleted the gh/vmoens/280/head branch May 18, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Collectors Feature New feature Integrations/torch_geometric Integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant