Skip to content

Unused renaming scheme make cache access via renamed name fail #535

@Butanium

Description

@Butanium

Even if a renaming is not used (model.language_model here):

from nnsight import LanguageModel

m = LanguageModel(
    "yujiepan/llama-3.2-tiny-random",
    rename={"model": "foo", "model.language_model": "foo"},
    # rename={"model": "foo"},  # works
)
with m.trace("Hello, world!") as tracer:
    cache = tracer.cache(modules=[m.foo.layers[0]])
print(cache.model.foo.layers[0].output)

It will make caching fail:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[7], line 10
      8 with m.trace("Hello, world!") as tracer:
      9     cache = tracer.cache(modules=[m.foo.layers[0]])
---> 10 print(cache.model.foo.layers[0].output)

File ~/projects/nnterp/.venv/lib/python3.10/site-packages/nnsight/intervention/tracing/tracer.py:156, in Cache.CacheDict.__getattr__(self, attr)
    154     name = self._alias[attr]
    155     name = name.removeprefix(".")
--> 156     return self.__getattr__(name)
    157 else:
    158     raise AttributeError(f"'{attr}' module path was never cached. '{self.__class__.__name__}' has no matching attribute.")

File ~/projects/nnterp/.venv/lib/python3.10/site-packages/nnsight/intervention/tracing/tracer.py:158, in Cache.CacheDict.__getattr__(self, attr)
    156     return self.__getattr__(name)
    157 else:
--> 158     raise AttributeError(f"'{attr}' module path was never cached. '{self.__class__.__name__}' has no matching attribute.")

AttributeError: 'model.language_model' module path was never cached. 'CacheDict' has no matching attribute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcache

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions