https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LibtorchRLMiniBatchSampler.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#ifdef MOOSE_LIBTORCH_ENABLED
11
12#pragma once
13
15
16#include <torch/torch.h>
17
18#include <cstdint>
19#include <vector>
20
25{
27 torch::Tensor observations;
29 torch::Tensor actions;
31 torch::Tensor old_log_probabilities;
33 torch::Tensor value_targets;
35 torch::Tensor advantages;
36
40 std::int64_t size() const { return observations.defined() ? observations.size(0) : 0; }
41};
42
47{
48public:
56 std::vector<LibtorchRLMiniBatch>
58 unsigned int batch_size,
59 bool standardize_advantage,
60 c10::optional<at::Generator> generator = c10::nullopt) const;
61
62private:
68
76 const torch::Tensor & indices,
77 bool standardize_advantage);
78};
79
80#endif
Samples shuffled mini-batches from a flattened on-policy trajectory batch.
static void validateBatch(const LibtorchRLTrajectoryBuffer::TensorBatch &batch)
Sanity-check that the flattened rollout tensors all line up.
std::vector< LibtorchRLMiniBatch > sample(const LibtorchRLTrajectoryBuffer::TensorBatch &batch, unsigned int batch_size, bool standardize_advantage, c10::optional< at::Generator > generator=c10::nullopt) const
Shuffle a flattened rollout batch into PPO-sized chunks.
static LibtorchRLMiniBatch makeMiniBatch(const LibtorchRLTrajectoryBuffer::TensorBatch &batch, const torch::Tensor &indices, bool standardize_advantage)
Slice one shuffled mini-batch out of the flattened rollout tensors.
Tensor data for one PPO mini-batch.
torch::Tensor actions
Action rows that match the sampled observations.
torch::Tensor value_targets
Critic targets aligned with the sampled observations.
std::int64_t size() const
Return the number of rows stored in the mini-batch.
torch::Tensor old_log_probabilities
Behavior-policy log probabilities for the sampled actions.
torch::Tensor advantages
Advantage estimates aligned with the sampled observations.
torch::Tensor observations
Flattened observation rows for the mini-batch.
Flattened tensor data assembled from the stored trajectories.