question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no data found for this tensor

See original GitHub issue

From @riatzukiza on March 18, 2018 18:52

Error

I was struggling with a memory leak, then I fix the leak, and I start getting this error.

bundle.js:14641 Uncaught (in promise) Error: WebGL backend: No data found for this tensor. Did you change your backend in the middle of the program? New backends can't use Tensors created with previous backends
    at MathBackendWebGL.throwIfNoData (bundle.js:14641)
    at MathBackendWebGL.readSync (bundle.js:14048)
    at MathBackendWebGL.<anonymous> (bundle.js:14093)
    at step (bundle.js:13922)
    at Object.next (bundle.js:13903)
    at fulfilled (bundle.js:13894)
    at <anonymous>

Code

I am rendering data to a canvas, so I have to call data every frame.

deeplearn logic

Logic to the implementation of conways game of life.

    var kernel = dl.reshape(dl.tensor2d([
        [1, 1, 1],
        [1, 0, 1],
        [1, 1, 1]
    ]), [3, 3, 1, 1]);
    var state0Tensor = dl.randomUniform([H, W]).greater(dl.scalar(0.5, "float32"));
    var state = dl.variable(dl.cast(dl.reshape(state0Tensor, [1, H, W, 1]), "float32"));
    var step = (function step$() {

        var newState = dl.tidy((() => {

            var neighbors = dl.conv2d(state, kernel, [1, 1, 1, 1], "same");
            var survive = dl.logicalAnd(dl.equal(state, dl.scalar(1, "float32")), dl.equal(neighbors, dl.scalar(2, "float32"))),
                born = dl.equal(neighbors, dl.scalar(3, "float32"));
            return dl.cast(dl.logicalOr(survive, born), "float32");

        }));
        state.assign(newState);
        newState.dispose();
        return state;
    });

rendering

Then I itterate over every element of tensor.data(), the error points at

return state.data().then(((d) => {
                            ^
    render(canvas = this.canvas, state = this.state, shape = this.shape, imageData = this.imageData, ctx = this.ctx) {

        if (!(running__QUERY)) {
            return false;
        };
        var height = shape[0],
            width = shape[1];
        return state.data().then(((d) => {

            var j = 0,
                k = 0;
            for (var i = 0; i < (width * height); ++(i)) {
                j = (i * 4);;
                this._renderCell(d[i], j, imageData)
            };
            return ctx.putImageData(imageData, 0, 0);

        }));

    }

Copied from original issue: tensorflow/tfjs-core#865

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nsthoratcommented, Apr 30, 2018

Ahhh yes! That makes a lot of sense. Basically what happens is you deep copy the tensor, the data ID also gets copied, but TensorFlow.js doesn’t know about it.

So the first Tensor gets cleaned up, destroying that data bucket (keyed by data ID). The next time you access the second data bucket we don’t know about it.

Just FYI, you can use “.clone()” to clone a Tensor. It will return a new Tensor, however clone() is extremely cheap. Under the covers we create another “shell” Tensor pointing to the same data ID.

Nice job finding that!

On Mon, Apr 30, 2018 at 8:39 AM, Grimmer notifications@github.com wrote:

After comparing the differences between the related codes for these 2 buttons, I got the key difference., thank you for your suggestions again.

// Coach.js // this.pnet is the instance of NNetWrapper this.pnet = deepcopy(this.nnet); //<-key point await this.nnet.train(flattenExamples); // start train

// NNet.js export class NNetWrapper extends NeuralNet { constructor(game) { // this.nnet is the instance of TicTacToeNNet, the same property name this.nnet = new TicTacToeNNet(game, args); } }

// TicTacToeNNet.js export default class TicTacToeNNet { constructor(game, args) { this.model = tf.model({ inputs: input, outputs: [output1, output2] }); } }

If I remove the line of this.pnet = deepcopy(this.nnet);, traning will not throw execpetions !!! (at least for my one time training test). Which means, if a object’s object’s property is tf.model, deepcopy this object will affect some internal state of TensorFlow.js/WebGL and the result is possible exceptioin.

Why I use deepcopy this object is to recoever the related tf.model to some saved state, if the following trained model is not good, it needs to go back to the previous status before training. Using deeocopy is my proposed workaround way, and the original Python version code uses tf.train.Saver().save/restore to achieve it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tensorflow/tfjs/issues/141#issuecomment-385386480, or mute the thread https://github.com/notifications/unsubscribe-auth/ABDLzcf9Vf_r2NfuFSo07jN62b8hgb0Hks5ttwXsgaJpZM4TLHXA .

0reactions
dsmilkovcommented, Oct 24, 2018

Since this issue, we’ve done global tracking of tensors, as well as transferring tensors between backends, so this error is likely outdated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why tensor board is showing "no scalar data is found"?
The tensorboard is launching before the model training starts, and says nothing is present. Then, if you try to re-run the cell, ...
Read more >
Reading data - TensorFlow
Reading data. There are three main methods of getting data into a TensorFlow program: Feeding: Python code provides the data when running each...
Read more >
tf.data: Build TensorFlow input pipelines
The tf.data API enables you to build complex input pipelines from simple, reusable pieces. For example, the pipeline for an image model might...
Read more >
torch.sparse — PyTorch 1.13 documentation
Only values and indices of non-zero elements are stored in this case. ... Constructing a new sparse COO tensor results a tensor that...
Read more >
torch_geometric.data — pytorch_geometric documentation
Add additional arguments to `data`: data.train_idx = torch.tensor([. ... KeyError – If the tensor corresponding to the input TensorAttr was not found.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found