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

Draft : Add infra to generate extra tensor #13486

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

zetwhite
Copy link
Contributor

@zetwhite zetwhite commented Jul 23, 2024

I moved the old draft(https://github.com/Samsung/ONE/pull/13326/files#diff-f4aa0ebe5af90acde526ab63faaa7352df19cfbfef06379f2dbeb8da5a5dab86) to new PR.
Because My old code and modifications are mixed up and I feel hard to debug.

@zetwhite zetwhite force-pushed the 0722/etensor branch 5 times, most recently from ae4c45b to dde2bbf Compare July 29, 2024 15:41
@zetwhite
Copy link
Contributor Author

@nnfw-bot test onert-x64-release

@hseok-oh
Copy link
Contributor

hseok-oh commented Jul 30, 2024

android build fail

/opt/jenkins_agent/workspace/nnfw/master/pr-onert-android-release/runtime/onert/backend/train/BackendContext.cc:238:42: error: captured structured bindings are a C++20 extension [-Werror,-Wc++20-extensions]
      extra_tensor_gen->register_tensors(operation_index, fn->requestExtraTensors());
                                         ^
/opt/jenkins_agent/workspace/nnfw/master/pr-onert-android-release/runtime/onert/backend/train/BackendContext.cc:235:15: note: 'operation_index' declared here
  for (auto &[operation_index, fn_seq] : ret)
              ^
1 error generated.

namespace train
{

class ExtraTensorGenerator
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this class necessary?

  • _idx_to_request can moved to TrainableGraph
  • plan() can be moved to TensorPlanner
  • allocate() is just a single line function

// Implement this if extra tensor is needed
virtual backend::train::ExtraTensorRequests requestExtraTensors()
{
backend::train::ExtraTensorRequests r;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Q) Why should this object be created in every TrainableFunction?

Copy link
Contributor Author

@zetwhite zetwhite Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, It isn't.
Only (Pool, Conv, DConv, FC, BinaryArithmetic) Layer requires ExtraTensors.

Copy link
Contributor Author

@zetwhite zetwhite Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put more comments here: https://github.com/Samsung/ONE/pull/13486/files#r1706502494

Is there a better way - not to create the object every time?

Comment on lines 267 to 269
fn_seq->iterate([&](exec::train::ITrainableFunction &fn) {
extra_tensor_gen.register_tensors(op_idx, (&fn)->requestExtraTensors());
});
Copy link
Contributor Author

@zetwhite zetwhite Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, ExtraTensorRequests are accessed through ITrainableFunction without downcasting to the specific layer. So, I'd like to define the interface function(?) in ITrainbleFunction.

@zetwhite zetwhite force-pushed the 0722/etensor branch 4 times, most recently from 6518364 to b3afcb1 Compare August 29, 2024 11:00
zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 11, 2024
This PR adds registerLayerScopeTensors to ITrainableFunction.
'registerLayerScopeTensors` is to register LayerScopeTensor into TensorReigstry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>
draft : Samsung#13486
for : Samsung#13282
zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 11, 2024
This PR adds registerLayerScopeTensors to ITrainableFunction.
'registerLayerScopeTensors` is to register LayerScopeTensor into TensorReigstry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>
draft : Samsung#13486
for : Samsung#13282
Comment on lines 62 to 72
std::optional<ExtraTensors> BinaryArithmeticLayer::registerExtraTensors()
{
ExtraTensors tensors;

if (_act_back_prop_output != nullptr)
{
tensors.push_back(_act_back_prop_output);
}

return std::optional<ExtraTensors>(tensors);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example of registerLayerScopeTensors usage

zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 13, 2024
This PR introduces LayerScopeMemoryManager.
This Manager will be added to TensorManager and used to allocate LayerScopeTensors.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

draft : Samsung#13486
for : Samsung#13282
zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 13, 2024
This PR introduces LayerScopeMemoryManager.
This Manager will be added to TensorManager and used to allocate LayerScopeTensors.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

draft : Samsung#13486
for : Samsung#13282
zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 13, 2024
This PR introduces LayerScopeMemoryManager.
This Manager will be added to TensorManager and used to allocate LayerScopeTensors.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

draft : Samsung#13486
for : Samsung#13282
zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 13, 2024
This PR adds LayerScopeTensors into TensorRegistry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

draft : Samsung#13486
for : Samsung#13282
chunseoklee pushed a commit that referenced this pull request Sep 20, 2024
This PR introduces LayerScopeMemoryManager.
This Manager will be added to TensorManager and used to allocate LayerScopeTensors.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

draft : #13486
for : #13282
zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 20, 2024
This PR adds LayerScopeManager into TensorManager.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

draft : Samsung#13486
for : Samsung#13282
zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 20, 2024
This PR adds LayerScopeTensors into TensorRegistry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

draft : Samsung#13486
for : Samsung#13282
zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 20, 2024
This PR adds LayerScopeTensors into TensorRegistry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

draft : Samsung#13486
for : Samsung#13282
zetwhite added a commit to zetwhite/ONE that referenced this pull request Sep 26, 2024
This PR adds LayerScopeManager into TensorManager.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

draft : Samsung#13486
for : Samsung#13282
Comment on lines +524 to +537
// forwading order
const auto f_order = _tgraph.topolSortOperations();
for (const auto &op_index : f_order)
{
if (not tensor_builder->isRegisteredLayerScopeTensor(op_index))
continue;

auto indices = tensor_builder->getRegisteredLayerScopeTensorIndex(op_index);
for (const auto &idx : indices)
{
const auto lt = tensor_builder->getLayerScopeTensorLifeTime(idx);
if (lt == LayerScopeTensorLifeTime::FORWARD_TO_BACKWARD)
tensor_builder->notifyLayerScopeFirstUse(idx);
}
Copy link
Contributor Author

@zetwhite zetwhite Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For planning, TensorBuilder has to provide

  • LayerScopeTensorIndex - matched by each OprationIndex
  • LifeTime information of each LayerScopeTensor.

zetwhite added a commit to zetwhite/ONE that referenced this pull request Oct 10, 2024
This PR adds TensorPlanner::planLayerScopeTensors() and its caller part in BackendContext.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

--------------------------------------

draft : Samsung#13486
zetwhite added a commit to zetwhite/ONE that referenced this pull request Oct 14, 2024
This PR adds TensorPlanner::planLayerScopeTensors() and its caller part in BackendContext.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

--------------------------------------

draft : Samsung#13486
zetwhite added a commit to zetwhite/ONE that referenced this pull request Oct 14, 2024
This PR adds TensorPlanner::planLayerScopeTensors() and its caller part in BackendContext.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

--------------------------------------

draft : Samsung#13486
zetwhite added a commit to zetwhite/ONE that referenced this pull request Oct 18, 2024
This PR registers LayerScopeTensor from each layer into tensor registry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

--------------------------------------

draft : Samsung#13486
zetwhite added a commit to zetwhite/ONE that referenced this pull request Oct 18, 2024
This PR registers LayerScopeTensor from each layer into tensor registry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

--------------------------------------

draft : Samsung#13486
zetwhite added a commit to zetwhite/ONE that referenced this pull request Oct 18, 2024
This PR registers LayerScopeTensor from each layer into tensor registry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

--------------------------------------

draft : Samsung#13486
zetwhite added a commit to zetwhite/ONE that referenced this pull request Oct 18, 2024
This PR registers LayerScopeTensor from each layer into tensor registry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

--------------------------------------

draft : Samsung#13486
chunseoklee pushed a commit that referenced this pull request Oct 21, 2024
This PR registers LayerScopeTensor from each layer into tensor registry.

ONE-DCO-1.0-Signed-off-by: seunghui youn <sseung.youn@samsung.com>

--------------------------------------

draft : #13486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants