Skip to content

TestAutograd::test_grad_ids_pre_post passes spuriously #2898

Closed

Description

@ngoldbaum

The test:

def test_grad_ids_pre_post(self):
def fun(arrs):
return arrs[0]
arrs = [mx.array(1.0)]
init_id = id(arrs[0])
mx.grad(fun)(arrs)
self.assertEqual(init_id, id(arrs[0]))

is supposed to check that passing a container to mx.grad doesn't mutate the items in the container. As noted in the docs for id(), two objects may have the same ids if they are never alive at the same time.

If I modify the test slightly:

import mlx.core as mx

def fun(arrs):
    return arrs[0]

arrs = [mx.array(1.0)]
arr = arrs[0]
mx.grad(fun)(arrs)
assert arr is arrs[0]

That fails. I think that means the test just happens to pass because of re-used ids.

This means #1854 didn't fix the issue the test is testing for, despite the guesswork here.

Originally posted by @ngoldbaum in #2807

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions