[go: nahoru, domu]

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

C++ API SparseApplyAdadelta segfaults due to lack of shape check #62978

Closed
Sehun0819 opened this issue Feb 16, 2024 · 5 comments
Closed

C++ API SparseApplyAdadelta segfaults due to lack of shape check #62978

Sehun0819 opened this issue Feb 16, 2024 · 5 comments
Assignees
Labels
comp:core issues related to core part of tensorflow comp:runtime c++ runtime, performance issues (cpu) stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author type:bug Bug

Comments

@Sehun0819
Copy link
Sehun0819 commented Feb 16, 2024

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

tf 2.17

Custom code

Yes

OS platform and distribution

Linux Ubuntu 22.04 LTS

Mobile device

No response

Python version

3.11.7

Bazel version

6.5.0

GCC/compiler version

clang 16

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

C++ API SparseApplyAdadelta segfaults due to lack of input shape check.

Error location:

  TF_RETURN_IF_ERROR(c->Merge(c->Dim(indices, 0), c->Dim(grad, 0), &unused));

At c->Dim(grad, 0), it reads 0th dim without checking rank of grad. Therefore when a scalar(0-rank) is given for arg grad it crashes.

Note that same things happen for other SparseApply* APIs(SparseApplyAdagrad, SparseApplyAdagradDA, SparseApplyFtrl, SparseApplyFtrlV2, SparseApplyMomentum, SparseApplyProximalAdagrad, SparseApplyProximalGradientDescent).

Standalone code to reproduce the issue

#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/cc/ops/array_ops.h"
#include "tensorflow/cc/ops/standard_ops.h"

using namespace tensorflow;

int main() {
  SessionOptions options;
  std::unique_ptr<tensorflow::Session>
    session(tensorflow::NewSession(options));

  Scope scope = Scope::NewRootScope();

  Input var = ops::Variable(scope, {1,1,1,1}, DT_FLOAT);
  Input accum = ops::Variable(scope, {1,1,1,1}, DT_FLOAT);
  Input accum_update = ops::Variable(scope, {1,1,1,1}, DT_FLOAT);
  auto target = ops::SparseApplyAdadelta(scope.WithOpName("target"), var, accum, accum_update, 0.1f, 0.1f, 0.1f, 0.1f, {1});

  GraphDef graph_def;
  TF_CHECK_OK(scope.ToGraphDef(&graph_def));

  Status status = session->Create(graph_def);
  if (!status.ok()) {
    LOG(FATAL) << "Could not create session: " << status.message();
  }

  std::vector<Tensor> outputs;
  status = session->Run({}, {"target"}, {""}, &outputs);
  if (!status.ok()) {
    LOG(FATAL) << "Could not run session: " << status.message();
  }

  return 0;
}

Relevant log output

Segmentation fault (core dumped)
@google-ml-butler google-ml-butler bot added the type:bug Bug label Feb 16, 2024
@tilakrayal tilakrayal added the comp:core issues related to core part of tensorflow label Feb 19, 2024
@codemania113
Copy link

Hi, I'm Paridhi and I'm new to this community. I would like to contribute, I've looked at the issues with labels - "good fist time" and "contribution welcome" but those issues are in stale state.
Please let me know if I can begin with this issue or any other relatively easier issue present in the queue. Thank you.

@tilakrayal tilakrayal added the comp:runtime c++ runtime, performance issues (cpu) label Feb 22, 2024
@SuryanarayanaY SuryanarayanaY added the awaiting review Pull request awaiting review label Mar 5, 2024
@tilakrayal
Copy link
Contributor

@Sehun0819,
The related PR which was proposed C++ API SparseApplyAdadelta segfaults due to lack of input shape check has been merged and also the changes are available in the training_ops.cc file

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/ops/training_ops.cc#L63

  const auto rank = c->Rank(grad);
  if (!rank) {
    return absl::InvalidArgumentError(absl::StrCat(
        "Argument grad must not be a scalar. ", "Got grad with rank ", rank));

Thank you!

@tilakrayal tilakrayal added stat:awaiting response Status - Awaiting response from author and removed awaiting review Pull request awaiting review labels Jun 12, 2024
Copy link

This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Jun 20, 2024
Copy link

This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:core issues related to core part of tensorflow comp:runtime c++ runtime, performance issues (cpu) stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author type:bug Bug
Projects
None yet
Development

No branches or pull requests

5 participants