Skip to content
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

Toolbox Features #7

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d69b403
Proxy __torch_function__ proxy arg may not always be first arg.
JadenFiotto-Kaufman Nov 14, 2023
b75dc1d
Cleaned up tutorial page and added tutorials for some features
cadentj Nov 16, 2023
73b56eb
Fix the doubling of gpu memory when using a custom model.
JadenFiotto-Kaufman Nov 16, 2023
dfe481a
Merge branch 'dev' of https://github.com/JadenFiotto-Kaufman/nnsight …
JadenFiotto-Kaufman Nov 16, 2023
33486ea
Fix patching. Move default patching to __init__
JadenFiotto-Kaufman Nov 16, 2023
f27a479
Documentation
JadenFiotto-Kaufman Nov 16, 2023
4892b95
Updating to work with remote server
JadenFiotto-Kaufman Nov 17, 2023
906830e
If a node has no listeners it wont be destroyed so check for that
JadenFiotto-Kaufman Nov 17, 2023
8b7713a
Method to dispatch/load local_model in AbstractModel.
JadenFiotto-Kaufman Nov 17, 2023
aa60864
Toolbox features drafts (and some notebooks)
cadentj Nov 18, 2023
49c26a2
Inference mode when scanning
JadenFiotto-Kaufman Nov 18, 2023
dc41b4f
Adding backwards input/output hooks! Dont call model.train/eval. Dont…
JadenFiotto-Kaufman Nov 19, 2023
27ee959
Merge branch 'dev' of https://github.com/JadenFiotto-Kaufman/nnsight …
JadenFiotto-Kaufman Nov 19, 2023
c1ef676
Need to clone proxy_value meta tensors for scanning so they are not l…
JadenFiotto-Kaufman Nov 19, 2023
eb81f4d
Include attribution patching notebook output
JadenFiotto-Kaufman Nov 20, 2023
eaa54e6
Enable retain_grad
JadenFiotto-Kaufman Nov 20, 2023
4c869c3
retain_grad example
JadenFiotto-Kaufman Nov 20, 2023
fcbbfc4
attribution patching one forward call
JadenFiotto-Kaufman Nov 21, 2023
ff3b15f
Bug fix for backwards hooks. Wrong order. Removed validating of proxy…
JadenFiotto-Kaufman Nov 28, 2023
59f322b
Use websocket secure
JadenFiotto-Kaufman Nov 28, 2023
9cc6a0b
ndif status in docs
JadenFiotto-Kaufman Nov 29, 2023
76da3f9
Merge branch 'dev' of https://github.com/JadenFiotto-Kaufman/nnsight …
JadenFiotto-Kaufman Nov 29, 2023
307eb5e
New logo
JadenFiotto-Kaufman Nov 29, 2023
4d73e47
Default remote to point to ndif.baulab.us
JadenFiotto-Kaufman Nov 29, 2023
3d50cda
ndif status
JadenFiotto-Kaufman Nov 29, 2023
c3e9e40
cropped logo
JadenFiotto-Kaufman Nov 29, 2023
dca0226
Updated logo and css colors
JadenFiotto-Kaufman Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="./docs/source/_static/images/nnsigt.png" alt="drawing" style="width:200px;float:left"/>
<img src="./docs/source/_static/images/nnsight_logo.svg" alt="drawing" style="width:200px;float:left"/>

# nnsight
![PyPI - Version](https://img.shields.io/pypi/v/nnsight)
Expand Down
5 changes: 4 additions & 1 deletion docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
}

html[data-theme="light"] {
--pst-color-secondary: #64ccdc;
--pst-color-secondary: #b676b2;
--pst-color-primary: #4ca4d2;
--pst-color-primary-highlight: #b676b2;

}


Expand Down
Binary file modified docs/source/_static/images/icon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions docs/source/_static/images/nnsight_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/source/_static/images/nnsigt.png
Binary file not shown.
27 changes: 27 additions & 0 deletions docs/source/_templates/ndif_status.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<style>
#ndif_status {
height: 18px;
width: 18px;
background-color: red;
border-radius: 50%;
display: inline-block;
margin-left: 10px;
}
</style>

<div>NDIF Status: </div><span id="ndif_status"></span>

<script>
console.log()
fetch("{{ndif_url}}")
.then((response) => {
if (response.status == 200) {
document.getElementById("ndif_status").style.backgroundColor = "green"
}
else {
document.getElementById("ndif_status").style.backgroundColor = "red"
}
})
.catch((response) => document.getElementById("ndif_status").style.backgroundColor = "red")

</script>
11 changes: 4 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
project = 'nnsight'
copyright = '2023, NDIF'
author = 'Jaden Fiotto-Kaufman'
release = '0.0.6'
release = '0.0.7'



# General Configuration

import sys
sys.path.append('/home/caden/Programming/nnsight/src/nnsight')

extensions = [
'sphinx.ext.autodoc', # Auto documentation from docstrings
'sphinx.ext.napoleon', # Support for NumPy and Google style docstrings
Expand All @@ -39,7 +35,7 @@
html_theme_options = {
"logo": {"text":"nnsight"},
"show_nav_level": 2,
"navbar_end": ["navbar-icon-links"],
"navbar_end": ["navbar-icon-links", "ndif_status"],
"navbar_align": "left",
"icon_links": [
{
Expand All @@ -51,7 +47,8 @@
}

html_context = {
"default_mode": "light"
"default_mode": "light",
"ndif_url" : "https://ndif.baulab.us/ping"
}

html_css_files = [
Expand Down
4 changes: 3 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ nnsight
.. grid-item::
.. div::

.. image:: _static/images/nnsigt.png
.. image:: _static/images/nnsight_logo.svg
:width: 400
:height: 276

.. grid-item::

Expand Down
30 changes: 29 additions & 1 deletion docs/source/tutorials.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
Tutorials
=========

Check out the :bdg-link-primary:`main demo <tutorials/notebooks/main_demo.ipynb>` for a quick walkthrough of important nnsight functionality. You can also check out more tutorials for the package below!

.. grid:: 2
:gutter: 3

.. grid-item-card:: Basics
:link: basics

Walk through the basic functionality of the package.

.. grid-item-card:: Features
:link: features

Learn some more advanced features of the package.

.. grid-item-card:: Toolkit

Familiarize yourself with the tools that come with the package. (Coming soon!)

.. grid-item-card:: Papers

See how nnsight can be applied through key papers in interpretability. (Coming soon!)




.. toctree::
:hidden:
:maxdepth: 1

tutorials/main_demo.ipynb
tutorials/basics
tutorials/features
7 changes: 7 additions & 0 deletions docs/source/tutorials/basics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Basics
======

.. toctree::
:maxdepth: 1

notebooks/main_demo.ipynb
9 changes: 9 additions & 0 deletions docs/source/tutorials/features.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Features
========

.. toctree::
:maxdepth: 1

notebooks/cross_prompt.ipynb
notebooks/multiple_token.ipynb
notebooks/token_indexing.ipynb
133 changes: 133 additions & 0 deletions docs/source/tutorials/notebooks/cross_prompt.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "5873a43e-e181-47d3-8ba9-2f6c9e7a7d61",
"metadata": {},
"source": [
"# Cross-Prompt Intervention"
]
},
{
"cell_type": "markdown",
"id": "1fb6417c-53dd-43d4-900b-7fdb9616591c",
"metadata": {},
"source": [
"Intervention operations work cross prompt! Use two invocations within the same generation block and operations can work between them.\n",
"\n",
"In this case, we grab the token embeddings coming from the first prompt, \"Madison square garden is located in the city of New\" and replace the embeddings of the second prompt with them."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "455cfa6f-54d6-43b7-befd-6754d6baa9e8",
"metadata": {},
"outputs": [],
"source": [
"from nnsight import LanguageModel\n",
"\n",
"model = LanguageModel('gpt2', device_map='cuda')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "50c3b04f-a9dc-4f01-9010-a93751745a47",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"You're using a GPT2TokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Madison square garden is located in the city of New York City.\n",
"_ _ _ _ _ _ _ _ _ _ York City.\n"
]
}
],
"source": [
"with model.generate(max_new_tokens=3) as generator:\n",
" \n",
" with generator.invoke(\"Madison square garden is located in the city of New\") as invoker:\n",
"\n",
" embeddings = model.transformer.wte.output\n",
"\n",
" with generator.invoke(\"_ _ _ _ _ _ _ _ _ _\") as invoker:\n",
"\n",
" model.transformer.wte.output = embeddings\n",
"\n",
"print(model.tokenizer.decode(generator.output[0]))\n",
"print(model.tokenizer.decode(generator.output[1]))"
]
},
{
"cell_type": "markdown",
"id": "5c70184c-239d-4964-94bc-56f5d4fea363",
"metadata": {},
"source": [
"We also could have entered a pre-saved embedding tensor as shown here:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "808f77a3-a43c-4564-a47b-0f1b1da6c79b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Madison square garden is located in the city of New York City.\n",
"_ _ _ _ _ _ _ _ _ _ York City.\n"
]
}
],
"source": [
"with model.generate(max_new_tokens=3) as generator:\n",
" \n",
" with generator.invoke(\"Madison square garden is located in the city of New\") as invoker:\n",
"\n",
" embeddings = model.transformer.wte.output.save()\n",
"\n",
"print(model.tokenizer.decode(generator.output[0]))\n",
"\n",
"with model.generate(max_new_tokens=3) as generator:\n",
"\n",
" with generator.invoke(\"_ _ _ _ _ _ _ _ _ _\") as invoker:\n",
"\n",
" model.transformer.wte.output = embeddings.value\n",
"\n",
"print(model.tokenizer.decode(generator.output[0]))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading