• Stars
    star
    436
  • Rank 99,320 (Top 2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Prompt programming with FMs.

Manifest

How to make prompt programming with Foundation Models a little easier.

Table of Contents

Install

Install:

pip install manifest-ml

Install with diffusion support:

pip install manifest-ml[diffusers]

Install with HuggingFace local model support:

pip install manifest-ml[api]

Dev Install:

git clone [email protected]:HazyResearch/manifest.git
cd manifest
make dev

Getting Started

Running is simple to get started. If using OpenAI, set export OPENAI_API_KEY=<OPENAIKEY> (or pass key in through variable client_connection) then run

from manifest import Manifest

# Start a manifest session to OpenAI - default `engine=text-davinci-003`
manifest = Manifest(
    client_name = "openai",
)
manifest.run("Why is the grass green?")

Examples

We have example notebook and python scripts located at examples. These show how to use different models, model types (i.e. text, diffusers, or embedding models), and async running.

Manifest Components

Manifest is meant to be a very light weight package to help with prompt design and iteration. Three key design decisions of Manifest are

  • All models are behind APIs
  • Supports caching of model inputs/outputs for iteration, reproducibility, and cost saving
  • Unified API to support generate, score, and embed

Models

Manifest provides model clients for OpenAI, AI21, Cohere, Together, and HuggingFace (see below for how to use locally hosted HuggingFace models). You can toggle between the models by changing client_name and client_connection. For example, if a HuggingFace model is loaded locally, run

manifest = Manifest(
    client_name = "huggingface",
    client_connection = "http://127.0.0.1:5000",
)

If you want to use Cohere, run

manifest = Manifest(
    client_name = "cohere",
    client_connection = <COHERE_API_KEY>,
)

You can also just set export COHERE_API_KEY=<COHERE_API_KEY> and not use client_connection.

If you want to use AI21 Labs, run

manifest = Manifest(
    client_name = "ai21",
    client_connection = <AI21_API_KEY>,
)

You can see the model details and possible model inputs to run() via

print(manifest.client_pool.get_current_client().get_model_params())
print(manifest.client_pool.get_current_client().get_model_inputs())

Global Cache

We support having queries and results stored in a global cache that can be shared across users. We treat inputs and outputs as key value pairs and support SQLite or Redis backends. To start with global caching using SQLite, run

manifest = Manifest(
    client_name = "openai",
    cache_name = "sqlite",
    cache_connection = "mycache.sqlite",
)

The cache will be saved in mycache.sqlite.

We also support Redis backend.

manifest = Manifest(
    client_name = "openai",
    cache_name = "redis",
    cache_connection = "localhost:6379"
)

As a hint, if you want to get Redis running, see the docker run command below under development.

Running Queries

Once you have a session open, you can write and develop prompts.

result = manifest.run("Hello, my name is Laurel")

You can also run over multiple examples if supported by the client.

results = manifest.run(["Where are the cats?", "Where are the dogs?"])

We support async queries as well via

import asyncio
results = asyncio.run(manifest.arun_batch(["Where are the cats?", "Where are the dogs?"]))

If something doesn't go right, you can also ask to get a raw manifest Response.

result_object = manifest.run(["Where are the cats?", "Where are the dogs?"], return_response=True)
print(result_object.get_request_obj())
print(result_object.is_cached())
print(result_object.get_response_obj())

By default, we do not truncate results based on a stop token. You can change this by either passing a new stop token to a Manifest session or to a run.

result = manifest.run(prompt, "Laurel", stop_token="and")

If you want to change default parameters to a model, we pass those as kwargs to the client.

result = manifest.run(prompt, "Laurel", max_tokens=50)

Streaming Queries

Manifest also supports streaming the model response back, assuming it's supported by the underlying client. When calling run, pass stream=True to get a streaming iterator in response.

result_iterator = manifest.run("Tell me a story. Once upon a time", max_tokens=100, stream=True)
for res_text in result_iterator:
    print(res_text)

Streaming responses are only supported for single string queries (not batch mode) for text completion models.

Model Pools

Manifest supports querying multiple models with different schedulers. This is very much a work in progress effort, but Manifest will round robin select (or randomly select) the clients you want. You can use the same client multiple times with different connection strings (e.g. different API keys), or you can mix and match. The only requirement is that all clients are the same request type. I.e. you can't have a pool of generation models and embedding models.

To query between a local model and OpenAI,

from manifest.connections.client_pool import ClientConnection
from manifest import Manifest

client_connection1 = ClientConnection(
    client_name="huggingface",
    client_connection="http://127.0.0.1:5000",
)
client_connection2 = ClientConnection(client_name="openai", engine="text-ada-001")
manifest = Manifest(
    client_pool=[client_connection1, client_connection2],
    cache_name="sqlite",
    client_connection=sqlite_cache,
)
manifest.run(...)

The speed benefit comes in with async batched runs. When calling arun_batch with a list of prompts, Manifest supports a chunk_size param. This will break the prompts into chunk_size chunks to spread across the client pool. By default chunk_size is -1 which means only one client will get all the prompts to run asynchronously. You must set chunk_size > 1 to distribute across the pool. There is a further batch_size param which control the individual client batch_size to send to the model.

responses = asyncio.run(manifest.arun_batch(prompts, max_tokens=30, chunk_size=20))

Other Models

Local Huggingface Models

To use a HuggingFace generative model, in manifest/api we have a Flask application that hosts the models for you.

In a separate terminal or Tmux/Screen session, to load 6B parameters models, run

python3 -m manifest.api.app \
    --model_type huggingface \
    --model_name_or_path EleutherAI/gpt-j-6B \
    --device 0

You will see the Flask session start and output a URL http://127.0.0.1:5000. Pass this in to Manifest. If you want to use a different port, set the FLASK_PORT environment variable.

manifest = Manifest(
    client_name = "huggingface",
    client_connection = "http://127.0.0.1:5000",
)

If you have a custom model you trained, pass the model path to --model_name_or_path.

To help load larger models, we also support using parallelize() from HF, accelerate, bitsandbytes, and deepspeed. You will need to install these packages first via pip install manifest-ml[api]. We list the commands to load larger models below.

  • T0pp
python3 -m manifest.api.app \
    --model_type huggingface \
    --model_name_or_path bigscience/T0pp \
    --use_hf_parallelize
  • NeoX 20B (requires at least 60GB of GPU memory)
python3 -m manifest.api.app \
    --model_type huggingface \
    --model_name_or_path EleutherAI/gpt-neox-20b \
    --use_accelerate_multigpu \
    --percent_max_gpu_mem_reduction 0.75
  • Bloom 175B (requires at least 240GB of GPU memory)
python3 -m manifest.api.app \
    --model_type huggingface \
    --model_name_or_path bigscience/bloom \
    --use_bitsandbytes \
    --percent_max_gpu_mem_reduction 0.85

Chat Models

Manifest has specific support for executing against chat models in the more standard "system" / "user" dialogue. To pass in a dialogue history to Manifest, use the run command with a list of dictionary inputs with role and content keys using an associated chat model such as openaichat.

manifest = Manifest(client_name="openaichat")
dialogue = [
    {"role": "system", "content": "You are a helpful assistant who also responds in rhymes"},
    {"role": "user", "content": "What is the date?"},
]
res = manifest.run(dialogue, max_tokens=100)

Embedding Models

Manifest also supports getting embeddings from models and available APIs. We do this all through changing the client_name argument. You still use run and abatch_run.

To use OpenAI's embedding models, simply run

manifest = Manifest(client_name="openaiembedding")
embedding_as_np = manifest.run("Get me an embedding for a bunny")

As explained above, you can load local HuggingFace models that give you embeddings, too. If you want to use a standard generative model, load the model as above use use client_name="huggingfaceembedding". If you want to use a standard embedding model, like those from SentenceTransformers, load your local model via

python3 -m manifest.api.app \
    --model_type sentence_transformers \
    --model_name_or_path all-mpnet-base-v2 \
    --device 0

Road Map

Here's what's coming up next

  • Clients
    • HuggingFace Hub
    • Azure OpenAI
    • Google Vertex
    • Anthropic
    • Streaming Support Completions
    • Streaming Support Chat Models
  • Data Types
    • Diffusion Models
  • Orchestration
    • Connection pools
  • Local Inference
    • FlexGen

Development

Before submitting a PR, run

export REDIS_PORT="6379"  # or whatever PORT local redis is running for those tests
cd <REDIS_PATH>
docker run -d -p 127.0.0.1:${REDIS_PORT}:6379 -v `pwd`:`pwd` -w `pwd` --name manifest_redis_test redis
make test

Cite

Please cite Manifest if you used it for any publications. Thanks!!

@misc{orr2022manifest,
  author = {Orr, Laurel},
  title = {Manifest},
  year = {2022},
  publisher = {GitHub},
  howpublished = {\url{https://github.com/HazyResearch/manifest}},
}

More Repositories

1

flash-attention

Fast and memory-efficient exact attention
Python
3,673
star
2

deepdive

DeepDive
Shell
1,951
star
3

ThunderKittens

Tile primitives for speedy kernels
Cuda
1,490
star
4

state-spaces

Sequence Modeling with Structured State Spaces
Jupyter Notebook
1,372
star
5

data-centric-ai

Resources for Data Centric AI
TeX
1,085
star
6

safari

Convolutions for Sequence Modeling
Assembly
855
star
7

meerkat

Creative interactive views of any dataset.
Python
821
star
8

hgcn

Hyperbolic Graph Convolutional Networks in PyTorch.
Python
576
star
9

hyena-dna

Official implementation for HyenaDNA, a long-range genomic foundation model built with Hyena
Assembly
566
star
10

ama_prompting

Ask Me Anything language model prompting
Python
534
star
11

m2

Repo for "Monarch Mixer: A Simple Sub-Quadratic GEMM-Based Architecture"
Assembly
525
star
12

H3

Language Modeling with the H3 State Space Model
Assembly
505
star
13

evaporate

This repo contains data and code for the paper "Language Models Enable Simple Systems for Generating Structured Views of Heterogeneous Data Lakes"
Python
475
star
14

metal

Snorkel MeTaL: A framework for training models with multi-task weak supervision
Python
422
star
15

pdftotree

🌲 A tool for converting PDF into hOCR with text, tables, and figures being recognized and preserved.
Python
413
star
16

fonduer

A knowledge base construction engine for richly formatted data
Python
406
star
17

hyperbolics

Hyperbolic Embeddings
Python
368
star
18

flyingsquid

More interactive weak supervision with FlyingSquid
Python
311
star
19

legalbench

An open science effort to benchmark legal reasoning in foundation models
Python
306
star
20

aisys-building-blocks

Building blocks for foundation models.
279
star
21

flash-fft-conv

FlashFFTConv: Efficient Convolutions for Long Sequences with Tensor Cores
C++
261
star
22

KGEmb

Hyperbolic Knowledge Graph embeddings.
Python
245
star
23

bootleg

Self-Supervision for Named Entity Disambiguation at the Tail
Python
211
star
24

based

Code for exploring Based models from "Simple linear attention language models balance the recall-throughput tradeoff"
Python
199
star
25

HypHC

Hyperbolic Hierarchical Clustering.
Python
188
star
26

TART

TART: A plug-and-play Transformer module for task-agnostic reasoning
Python
187
star
27

fly

Python
181
star
28

tanda

Learning to Compose Domain-Specific Transformations for Data Augmentation
Python
169
star
29

spacetime

Code for SpaceTime 🌌⏱️. Proposed in Effectively Modeling Time Series with Simple Discrete State Spaces, ICLR 2023.
Python
158
star
30

butterfly

Butterfly matrix multiplication in PyTorch
Python
158
star
31

zoology

Understand and test language model architectures on synthetic tasks.
Python
157
star
32

hippo-code

Python
151
star
33

babble

A system for generating training labels via natural language explanations
Python
145
star
34

EmptyHeaded

Your worst case is our best case.
C++
136
star
35

domino

Python
132
star
36

blocking-tutorial

C++
131
star
37

mindbender

Tools for iterative knowledge base development with DeepDive
CoffeeScript
116
star
38

reef

Automatically labeling training data
Jupyter Notebook
105
star
39

fonduer-tutorials

A collection of simple tutorials for using Fonduer
Jupyter Notebook
100
star
40

fm_data_tasks

Foundation Models for Data Tasks
Python
96
star
41

TreeStructure

Table Extraction Tool
Jupyter Notebook
89
star
42

CaffeConTroll

C++
76
star
43

eclair-agents

Automating enterprise workflows with multimodal agents
Jupyter Notebook
76
star
44

epoxy

Interactive Model Iteration with Weak Supervision and Pre-Trained Embeddings
Python
76
star
45

HoroPCA

Hyperbolic PCA via Horospherical Projections
Python
64
star
46

structured-nets

Structured matrices for compressing neural networks
Python
64
star
47

hidden-stratification

Combating hidden stratification with GEORGE
Jupyter Notebook
61
star
48

numbskull

Numba-based version of DimmWitted Gibbs sampler
Python
46
star
49

model-patching

Model Patching: Closing the Subgroup Performance Gap with Data Augmentation
Python
42
star
50

skill-it

Skill-It! A Data-Driven Skills Framework for Understanding and Training Language Models
Jupyter Notebook
36
star
51

cs145-notebooks-2016

Public materials for the Fall 2016 offering of CS145
Jupyter Notebook
35
star
52

mandoline

(ICML 2021) Mandoline: Model Evaluation under Distribution Shift
Python
30
star
53

mongoose

A Learnable LSH Framework for Efficient NN Training
Python
29
star
54

thanos-code

Code release for the paper Perfectly Balanced: Improving Transfer and Robustness of Supervised Contrastive Learning
Python
29
star
55

prefix-linear-attention

Python
27
star
56

tuffy

Tuffy, a Markov Logic Network solver
Java
23
star
57

ukb-cardiac-mri

Weakly Supervised MRI Series Classification for the UK Biobank
Python
23
star
58

snorkel-superglue

Applying Snorkel to SuperGLUE
Jupyter Notebook
23
star
59

correct-n-contrast

Official code repository for Correct-N-Contrast
Python
21
star
60

ludwig-benchmarking-toolkit

Ludwig benchmark
Python
19
star
61

ddlog

Compiler for writing DeepDive applications in a Datalog-like language — ⚠️🚧🛑 REPO MOVED TO DEEPDIVE 👇🏿
Scala
19
star
62

augmentation_code

Reproducible code for Augmentation paper
Python
18
star
63

smallfry

Python
18
star
64

tabi

Code release for Type-Aware Bi-Encoders for Open-Domain Entity Retrieval
Python
18
star
65

lp_rffs

Low precision random Fourier features for kernel approximation
Python
17
star
66

sampler

DimmWitted Gibbs Sampler in C++ — ⚠️🚧🛑 REPO MOVED TO DEEPDIVE 👉🏿
C++
17
star
67

random_embedding

Python
16
star
68

snorkel-biocorpus

Python
16
star
69

bazaar

JavaScript
14
star
70

ddbiolib

DeepDive Biomedical Tools
Python
14
star
71

anchor-stability

A study of the downstream instability of word embeddings
Jupyter Notebook
13
star
72

Omnivore

Omnivore Optimizer and Distributed CcT
C++
13
star
73

wonderbread

WONDERBREAD benchmark + dataset for BPM tasks
Jupyter Notebook
13
star
74

embroid

Embroid: Unsupervised Prediction Smoothing Can Improve Few-Shot Classification
Jupyter Notebook
12
star
75

dd-genomics

The Genomics DeepDive project
Python
11
star
76

medical-ned-integration

Cross-domain data integration for named entity disambiguation in biomedical text
Python
10
star
77

dimmwitted

C++
10
star
78

torchhalp

Python
9
star
79

cross-modal-ws-demo

HTML
9
star
80

hyperE

HTML
8
star
81

treedlib

Jupyter Notebook
8
star
82

Accelerated-PCA

Accelerated Stochastic Power Iteration with Momentum
Jupyter Notebook
8
star
83

liger

Liger: Fusing Weak Supervision and Model Embeddings
Python
8
star
84

ivy-tutorial

An Introductory Tutorial for Ivy
Jupyter Notebook
7
star
85

chinstrap

C++
6
star
86

observational

Observational Supervision for Medical Image Classification using Gaze Data
Jupyter Notebook
6
star
87

quadrature-features

Code to generate kernel features using Gaussian quadrature
Python
5
star
88

icij-maude

Weakly supervised classification of adverse event reports from the FDA's MAUDE database.
Python
5
star
89

librarian

DeepDive Librarian for managing all data sets we publish and receive
Python
3
star
90

halp

Python
3
star
91

bert-pretraining

Python
2
star
92

d3m-model-search

D3M Model Search Component
Python
2
star
93

elementary

Data services and APIs
Python
1
star
94

dependency_model

Structure learning code from [ICML'19 paper](https://arxiv.org/abs/1903.05844)
Python
1
star