GithubHelp home page GithubHelp logo

web-logs2 / manifest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fliaping/manifest

0.0 0.0 0.0 3.19 MB

Prompt programming with FMs.

License: Apache License 2.0

Python 99.61% Makefile 0.39%

manifest's Introduction

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-002`
manifest = Manifest(
    client_name = "openai",
)
manifest.run("Why is the grass green?")

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 of 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.

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

print(manifest.client.get_model_params())
print(manifest.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?"])

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())
print(result_object.is_cached())
print(result_object.get_json_response())

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)

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

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}},
}

manifest's People

Contributors

lorr1 avatar yichern avatar anarayan avatar seyuboglu avatar bnewm0609 avatar thakkarparth007 avatar fliaping avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.