static Tensor *requestTensor_(const TensorSpecV2 &spec,
const GraphNode::ExecutionOrder &exec_order,
- const std::string &scope, TensorPool &tp) {
+ const std::string &scope, TensorPool &tp,
+ bool expose) {
using RT = TensorSpecV2::RequestType;
using LS = TensorLifespan;
NNTR_THROW_IF(spec.request_type == RT::MAYBE_MODIFYING_VIEW,
auto [forward, calc_grad, calc_deriv] = exec_order;
std::vector<unsigned> order = spec.additional_exec_order;
+ if (expose) {
+ order.push_back(TensorPool::PERSIST_END_ORDER);
+ }
const auto name = scope + ":" + spec.name;
<< "Currently, input and tensors group type is not yet implemented, use "
"requestInputs() requestTensors() instead";
- Tensor *var =
- requestTensor_(spec.variable_spec, exec_order, scope, tensor_pool);
- Tensor *grad =
- spec.gradient_spec
- ? requestTensor_(*spec.gradient_spec, exec_order, scope, tensor_pool)
- : nullptr;
+ Tensor *var = requestTensor_(spec.variable_spec, exec_order, scope,
+ tensor_pool, expose_var);
+ Tensor *grad = spec.gradient_spec
+ ? requestTensor_(*spec.gradient_spec, exec_order, scope,
+ tensor_pool, expose_grad)
+ : nullptr;
/// @note as only supporting identify_as == TensorGroupType::output, only
/// saves to outputs for now
*/
std::vector<Weight *> Manager::requestWeights(
const GraphNode &node, const std::vector<Weight::Spec> &weights_spec,
- bool trainable, const std::vector<std::string> &shared_names,
- const unsigned int max_exec_order) {
+ bool trainable, const std::vector<std::string> &shared_names) {
const auto [forwarding_order, calcGradient_order, calcDerivative_order] =
node.getExecutionOrder();
+
std::vector<unsigned int> var_exec_order(
{forwarding_order, calcGradient_order, calcDerivative_order});
std::vector<unsigned int> default_grad_exec_order(
* applied to the weight.
*/
if (Weight::isGradientClipByGlobalNorm(clip_by_global_norm))
- grad_exec_order.push_back(max_exec_order);
+ grad_exec_order.push_back(TensorPool::PERSIST_END_ORDER);
Tensor *var = nullptr, *grad = nullptr;
bool is_dependent = !shared_names.empty();
inputs_v2.emplace_back(std::make_unique<Var_Grad>(
requestTensor_(var_spec, node.getExecutionOrder(), node.getName(),
- tensor_pool),
+ tensor_pool, false),
requestTensor_(grad_spec, node.getExecutionOrder(), node.getName(),
- tensor_pool)));
+ tensor_pool, false)));
}
ret.reserve(inputs_dim.size());
* @param trainable make the weight trainable if true
* @param shared_names name to refer to when the weights are borrowed from the
* original source. if not shared pass empty vector
- * @param max_exec_order the maximum execution order
*
* @return created weights list
*/
std::vector<Weight *>
requestWeights(const GraphNode &node,
const std::vector<Weight::Spec> &weights_spec, bool trainable,
- const std::vector<std::string> &shared_names,
- const unsigned int max_exec_order);
+ const std::vector<std::string> &shared_names);
/**
* @brief Create tensors with the given spec