Skip to main content

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.

Metadata

Release files for seperability 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seperability 0.1.3
File Size Uploaded
seperability-0.1.3.tar.gz 24.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for seperability 0.1.3
File Interpreter ABI Platform
seperability-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 48.1 kB

Release files / seperability-0.1.3.tar.gz

Download URL seperability-0.1.3.tar.gz
Size 24.1 kB
Tags Source
SHA-256 checksum
How to use checksums
abd4b49836379fe1afec81d576801e9d5ca79506c7412943a89e34f63bf98622
BLAKE2b-256 checksum
How to use checksums
31bba3b93ef5e64fee7dd1c79d16995c656327a80b8d1f71e9f3371c1f12fcc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.9 Darwin/22.1.0

Release files / seperability-0.1.3-py3-none-any.whl

Download URL seperability-0.1.3-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88f890bdcac714aa4755aac0e74ad6aa327ff357f845b265399d3983fabd09d8
BLAKE2b-256 checksum
How to use checksums
3060226f7080e8bba4d2d63656221a29740db885349e3ecd32854cc942afb10a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.9 Darwin/22.1.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page