ndif-team / nnsight

The nnsight package enables interpreting and manipulating the internals of deep learned models.
https://nnsight.net/
MIT License
356 stars 34 forks source link

Iterator context optionally returns Iterator object #198

Closed AdamBelfki3 closed 3 weeks ago

AdamBelfki3 commented 3 weeks ago

Accessing the Iterator object when creating an Iterator context has become optional.

with model.session() as session:
    l  = session.apply(list).save()
    with session.iter([0, 1, 2]) as item:
        l.append(item)

print("List: ", l)
"List: [0, 1, 2]"

If you wish to use the Iterator, simply set return_context=True.

with model.session() as session:
    l  = session.apply(list).save()
    with session.iter([0, 1, 2], return_context=True) as (item, iterator):
        l.append(item)
        iterator.exit()

print("List: ", l)
"List: [0]"