A user toolkit for analyzing and interfacing with Large Language Models (LLMs)
Project description
Kaleidoscope-SDK
A user toolkit for analyzing and interfacing with Large Language Models (LLMs)
Overview
kaleidoscope-sdk
is a Python module used to interact with large language models
hosted via the Kaleidoscope service available at: https://github.com/VectorInstitute/kaleidoscope.
It provides a simple interface to launch LLMs on an HPC cluster, asking them to
perform basic features like text generation, but also retrieve intermediate
information from inside the model, such as log probabilities and activations.
These features are exposed via a few high-level APIs, namely:
model_instances
- Shows a list of all active LLMs instantiated by the model serviceload_model
- Loads an LLM via the model servicegenerate
- Returns an LLM text generation based on prompt inputmodule_names
- Returns all modules names in the LLM neural networkget_activations
- Retrieves all activations for a set of modules
Getting Started
Requires Python version >= 3.8
Install
python3 -m pip install kscope
or install from source:
pip install git+https://github.com/VectorInstitute/kaleidoscope-sdk.git
Authentication
In order to submit generation jobs, a designated Vector Institute cluster account is required. Please contact the AI Engineering Team in charge of Kaleidoscope for more information.
Sample Workflow
The following workflow shows how to load and interact with an OPT-175B model on the Vector Institute Vaughan cluster.
#!/usr/bin/env python3
import kscope
import time
# Establish a client connection to the Kaleidoscope service
# If you have not previously authenticated with the service, you will be prompted to now
client = kscope.Client(gateway_host="llm.cluster.local", gateway_port=3001)
# See which models are supported
client.models
# See which models are instantiated and available to use
client.model_instances
# Get a handle to a model. If this model is not actively running, it will get launched in the background.
# In this example we want to use the OPT-175B model
opt_model = client.load_model("OPT-175B")
# If the model was not actively running, this it could take several minutes to load. Wait for it come online.
while opt_model.state != "ACTIVE":
time.sleep(1)
# Sample text generation w/ input parameters
text_gen = opt_model.generate("What is the answer to life, the universe, and everything?", {'max_tokens': 5, 'top_k': 4, 'temperature': 0.5})
dir(text_gen) # display methods associated with generated text object
text_gen.generation['text'] # display only text
text_gen.generation['logprobs'] # display logprobs
text_gen.generation['tokens'] # display tokens
# Now let's retrieve some activations from the model
# First, show a list of modules in the neural network
print(opt_model.module_names)
# Setup a request for module acivations for a certain module layer
requested_activations = ['decoder.layers.0']
activations = opt_model.get_activations("What are activations?", requested_activations)
print(activations)
Documentation
Full documentation and API reference are available at: http://kaleidoscope-sdk.readthedocs.io.
Contributing
Contributing to kaleidoscope is welcomed. See Contributing for guidelines.
License
Citation
Reference to cite when you use Kaleidoscope in a project or a research paper:
Sivaloganathan, J., Coatsworth, M., Willes, J., Choi, M., & Shen, G. (2022). Kaleidoscope. http://VectorInstitute.github.io/kaleidoscope. computer software, Vector Institute for Artificial Intelligence. Retrieved from https://github.com/VectorInstitute/kaleidoscope-sdk.git.
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
Built Distribution
File details
Details for the file kscope-0.4.1.tar.gz
.
File metadata
- Download URL: kscope-0.4.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c817855e2c4958bc41f0ad9afd129fd7418273deaf32221c971a3b5d06839211 |
|
MD5 | d81b7566ef0ea88cef39caf00fa250df |
|
BLAKE2b-256 | 475c217d5d3b05faa072d4daddbff74ec35d58c26c5f491de0feb15ccd3f7212 |
File details
Details for the file kscope-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: kscope-0.4.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1a0c843aea5d19da2503e2e68ca24adcb03141a03a5bcd96a2b5d0d5ad7a121 |
|
MD5 | f432063a8655b6be9a29e75148fe7620 |
|
BLAKE2b-256 | b25b856da428030910019be33f290898b011cbf41f1597280f8771d5ee44cf01 |