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

global nnsight support of python builtins #201

Closed AdamBelfki3 closed 3 weeks ago

AdamBelfki3 commented 3 weeks ago

New feature! You can now globally trace some Python builtin classes irrespective of the context you are in.

Here is the list of supported builtins:

Here is how you can use it:

import nnsight
from nnsight import LanguageModel

model = LanguageModel("openai-community/gpt2", device_map=True)

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

print("List: ", nn_list)
import nnsight
from nnsight import LanguageModel

model = LanguageModel("openai-community/gpt2, device_map=True)

with model.session() as session:
    nn_list = nnsight.list()
    with session.iter([0, 1, 2]) as item:
        nn_list.append(nnsight.int(item))

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