Coder Social home page Coder Social logo

rsnm2 / deepsparse-continuous-batching Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huggingface/text-generation-inference

1.0 0.0 0.0 2.26 MB

DeepSparse Continuous Batching

Home Page: https://huggingface.co/text-generation-inference

License: Apache License 2.0

Shell 0.04% JavaScript 0.15% C++ 0.55% Python 57.67% C 0.02% Rust 17.77% Cuda 4.62% Makefile 0.23% Dockerfile 0.55% Jupyter Notebook 18.39%

deepsparse-continuous-batching's Introduction

Install:

pip3 install deepsparse-nightly[transformers] fastapi uvicorn

Download model:

sparsezoo.download zoo:nlg/text_generation/codegen_multi-350m/pytorch/huggingface/bigquery_thepile/base_quant-none --save-dir codegen-quant

Launch server:

python3 deepsparse/server.py --deployment-dir ./codegen-quant/deployment

Make requests:

import requests
from threading import Thread
import json

url = "http://127.0.0.1:5543/generate"
sequence = "Write a function for computing a fibonacci sequence: \n\ndef fib(n):"
# sequence = "def fib(n):"

def request_task(max_new_tokens):
    obj = {
        "inputs": sequence,
        "generation_parameters": {
            "max_new_tokens":max_new_tokens,
            # "repetition_penalty": 1.1,
            # "do_sample": True,
            # "temperature": 1.1,
            # "top_k": 3,
            # "top_p": 0.9,
            # "seed": 42,
        }
    }
    with requests.post(url, json=obj) as r:
        print(max_new_tokens)
        dct = json.loads(r.text)
        # print(dct)
        print(f'{sequence}{dct["response_text"]}')

max_new_tokens_lst = [100, 50, 25]
request_ts = [
    Thread(target=request_task, args=[max_new_tokens]) 
    for max_new_tokens in max_new_tokens_lst
]

import time
for request_t in request_ts:
    request_t.start()
    time.sleep(0.1)

for request_t in request_ts:
    request_t.join()

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.