Code Monkey home page Code Monkey logo

simple_llm_inference's Introduction

Simple LLM Inference: Interactive Text Generation with Intel GPUs

LLM Inference example is a Python script designed to demonstrate interactive text generation using pre-trained Language Models (LLMs) from Hugging Face Transformers and Intel dGPUs. Although the code structure resembles a chatbot, it's important to note that the models used were not specifically trained for conversational purposes. This repository provides a Command Line Interface (CLI) to interact with the models in two modes: with context (remembering previous interactions) and without context. The code is optimized to run on Intel GPUs using Intel Extension for PyTorch (IPEX).

Features

  • Model Selection: Choose between predefined models or enter a custom model repository from Hugging Face Hub.
  • Context Control: Interact with the model in two modes, with and without context.
  • Generation Parameters Control: Customize the response generation by adjusting parameters like temperature, top_p, top_k, num_beams, and repetition_penalty.
  • Repetition Removal: The code includes logic to remove repetitive sentences from the generated text.

Prerequisites

  • Python 3.6 or higher
  • Intel Extension for PyTorch (IPEX)
  • Hugging Face Transformers
  • Hugging Face Accelerate

Setup

  1. Clone the repository
git clone https://github.com/rahulunair/simple_llm_inference.git && cd simple_llm_inference
  1. Install dependencies:
python -m pip install torch==2.0.1a0 torchvision==0.15.2a0 intel_extension_for_pytorch==2.0.110+xpu -f https://developer.intel.com/ipex-whl-stable-xpu
python -m pip install transformers accelerate sentencepiece

To know more about IPEX on Intel GPUs use the following guide.

Usage

  1. Run bot.py
python bot.py
  1. Follow the on-screen prompts to select a model and the interaction mode.

Sample output

Please select a model:
1. Writer/camel-5b-hf
2. openlm-research/open_llama_3b_v2
3. Enter a custom model repo from HuggingFace Hub
Enter 1 to 3: 2
Using max length: 256
Note: This is a demonstration using pretrained models which were not fine-tuned for chat.
You can choose between two modes of interaction:
1. Interact with context
2. Interact without context
Enter 1 or 2: 1
You: Hello, Bot!
Bot: Hello! How can I assist you today?

Contributing

Feel free to submit issues and pull requests. Contributions are welcome!

simple_llm_inference's People

Contributors

rahulunair avatar

Stargazers

 avatar

Watchers

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