-
Notifications
You must be signed in to change notification settings - Fork 9
Add notebook export to the Logit Lens tool #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AdamBelfki3
wants to merge
3
commits into
main
Choose a base branch
from
AdamBelfki3/logit-lens-notebook-export
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "e7693828", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Workspace" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "c801b72a", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Run Instructions\n", | ||
| "\n", | ||
| "This notebook runs the Logit Lens experiment exactly as it was run in your workspace, using the `nnsightful` library. `nnsightful` is the same library used by Workbench for Logit Lens. You should have this dependency installed before running the notebook." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "d7795c3f", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "For remote execution (`REMOTE=True`), ensure that `NDIF_API_KEY` is properly set in your environment: `os.environ[\"NDIF_API_KEY\"] = <API_KEY>`. \n", | ||
| "If you don't have a key, visit [login.ndif.us](https://login.ndif.us) to obtain yours and access all the models available on NDIF.\n", | ||
| "\n", | ||
| "A `HF_TOKEN` is also required, see [HF Login](https://huggingface.co/docs/huggingface_hub/quick-start#login-command)." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "47a7db44", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Setup" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "948742ee", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "try:\n", | ||
| " %pip install git+https://github.com/AdamBelfki3/nnsightful.git\n", | ||
| "\n", | ||
| " from IPython.display import clear_output\n", | ||
| " clear_output()\n", | ||
| "except Exception:\n", | ||
| " pass" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "f03096a0", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# CONFIG\n", | ||
| "MODEL_NAME = \"meta-llama/Llama-3.1-8B\"\n", | ||
| "REMOTE = True" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "d4db144b", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from nnterp import StandardizedTransformer\n", | ||
| "\n", | ||
| "model = StandardizedTransformer(\n", | ||
| " MODEL_NAME, \n", | ||
| " device_map=\"auto\", \n", | ||
| " dispatch=not REMOTE,\n", | ||
| " allow_dispatch=not REMOTE,\n", | ||
| " check_renaming= not REMOTE,\n", | ||
| " remote=False\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "c67ecd46", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Chart" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "169b2da6", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "**Logit Lens Parameters:**\n", | ||
| "\n", | ||
| "- `prompt` is the text whose intermediate-layer predictions you want to decode.\n", | ||
| "- `top_k` is the number of top predictions kept per cell.\n", | ||
| "- `include_entropy` toggles per-cell entropy computation." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "a9c50b11", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# PARAMETERS\n", | ||
| "prompt = \"\"\"The Eiffel Tower is located in the city of\"\"\"\n", | ||
| "top_k = 5\n", | ||
| "include_entropy = True" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "cell-10", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from nnsightful import logit_lens\n", | ||
| "\n", | ||
| "ll_data = logit_lens(\n", | ||
| " model,\n", | ||
| " prompt,\n", | ||
| " top_k=top_k,\n", | ||
| " include_entropy=include_entropy,\n", | ||
| " remote=REMOTE,\n", | ||
| ")\n", | ||
| "\n", | ||
| "ll_data.display()" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "be36655f", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Additional Experiments\n", | ||
| "\n", | ||
| "You can run additional experiments using `nnsightful` or other libraries below." | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": ".venv", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.12.3" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Honor
REMOTEwhen constructing the model.This cell hardcodes
remote=False, so the exported notebook won't reproduce remote execution even when the config cell setsREMOTE = True.Proposed fix
model = StandardizedTransformer( MODEL_NAME, device_map="auto", dispatch=not REMOTE, allow_dispatch=not REMOTE, check_renaming= not REMOTE, - remote=False + remote=REMOTE )📝 Committable suggestion
🤖 Prompt for AI Agents