Skip to main content

Seperability of LLM Capabilities

Project description

Seperability

My basic library for studying LLMs (currently, only the Meta OPT models). This includes functions for analysing the activations of the models for different inputs, and for pruning different parts of the model based on those activations.

Pruning based on Capabilities

For a full example, see src/seperability.ipynb.

The simple example is:

from model import Model
from activations import prune_and_evaluate, evaluate_all

# Load and Evaluate Model on Pile and Code

opt = Model('125m', limit=1000)
eval_data = evaluate_all(opt, 1e5)
print(eval_data)

# Prune Model, Removing coding capabilities (compared to pile), and evaluate

eval_data = prune_and_evaluate(opt, ff_prune_frac=0.05, attn_prune_frac=0.05,
    ff_eps=1e-3, sample_size=1e5, eval_size=1e5, cripple='code', focus='pile')
print(eval_data)

model.py

This defines a wrapper function that encapsulates the HuggingFace implementation of Meta OPT. To get the model, simply run:

from model import Model

opt = Model('125m', limit=1000)

Where you can provide any of the model sizes that are pre-trained for OPT, and the token limit must be smaller than the max token length that the model is able to handle.

Next, you can run the model to do 2 tokens of predictions, by, for example, running:

text = 'Hello, my name is'
inpt, output = opt.predict( text, num=2 )

We can look at the residual stream of how the output changes over time.

residual_stream = opt.get_residual_stream( text )

This will return a tensor of size 2 + 2*n_layers. i.e:

  • the input (w/ positional encoding)
  • n attention layer outputs
  • n feed forward layer outputs
  • the final output

If we want just the output of the attention / feed forward layers, we can instead look at the activations:

inpt, attn_out, ff_out, output = opt.get_text_activations( text )

or alternatively:

inpt, attn_out, ff_out, output = opt.get_text_activations( residual_stream=residual_stream )

To get the activations for the input text at all of the MLP mid layers, we can look at: opt.get_ff_key_activations( text ) or opt.get_ff_key_activations( residual_stream=residual_stream ).

texts.py

Has some basic tools for loading the two text datasets I am using:

  • 'the_pile' ( validation set of The Pile )
  • 'codeparrot-clean-valid' ( validation set of codeparrot )

activations.py

Has code specific to the two datasets I am using to analyze and attempt to remove capabilities from the OPT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

seperability-0.1.1.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

seperability-0.1.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file seperability-0.1.1.tar.gz.

File metadata

  • Download URL: seperability-0.1.1.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.8.0 Linux/5.15.0-58-generic

File hashes

Hashes for seperability-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b94d272397f7f992fce3343025a808b5d6718799028793daa6ff42916a4764f1
MD5 2657f5029171427e41df1ac54bf61319
BLAKE2b-256 0ef044c62203a733ffed9317b32a8729ea8aa252b4383eafa5a47cb0c29007e0

See more details on using hashes here.

File details

Details for the file seperability-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: seperability-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.8.0 Linux/5.15.0-58-generic

File hashes

Hashes for seperability-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 56e4ac69b4d33780495b92cb41403e580ce3c2031e8bd129dccd3785fb328ac9
MD5 de07fbcf04ef089fe44a45ba1633968c
BLAKE2b-256 5bf6d6a66393ed55ead37b50509ceda53915fb46ece03c1b99b9d0467e6b1611

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page