Skip to main content

Serve MESA models locally

Project description

MESA local

Serve MESA models locally.

  • ⬇️ Downloads weights from S3

  • 📦 Unpacks

  • 🚀 Serves via a local OpenAI-compatible server

Prerequisites

Software

  • Python 3.12

Hardware

  • A GPU with >=24GB VRAM (tested on NVIDIA A30)

Configuration

Create a file called .env in the directory where you intend to run this package. Populate it with the details you have been provided with in the following format:

MODEL_NAME=
WEIGHTS_ID=
WEIGHTS_KEY=

(Alternative) S3 URI

Download weights directly from an S3 bucket:

MODEL_NAME=
WEIGHTS_URI=
WEIGHTS_REGION=  # optional, defaults to eu-west-2

(Optional) Caching

Download weights and cache to S3 for faster subsequent downloads:

MODEL_NAME=
WEIGHTS_ID=
WEIGHTS_KEY=
WEIGHTS_URI=
WEIGHTS_REGION=  # optional, defaults to eu-west-2

With this configuration:

  • First run: Downloads weights and uploads to S3 cache

  • Subsequent runs: Downloads directly from S3 cache (faster)

vLLM configuration

The package provides a set of vLLM configuration files for running a specific model on a specific GPU. In addition to MODEL_NAME, this can be specified by adding GPU to the .env.

Individual vLLM settings can also be overridden by adding them to the .env file:

Setting Alias Type Default
MODEL MODEL_NAME str mesalocal
GPU str None
MAX_MODEL_LEN MODEL_LENGTH int 41152
ENFORCE_EAGER bool False
ENABLE_CHUNKED_PREFILL bool True
ENABLE_PREFIX_CACHING bool True
GPU_MEMORY_UTILIZATION float 0.9
MAX_NUM_SEQS int 256
MAX_NUM_BATCHED_TOKENS int None
ENABLE_LOG_REQUESTS bool False
UVICORN_LOG_LEVEL str warning
HTTP_TIMEOUT_KEEP_ALIVE int 30

Installation

  1. (Recommended) Create a virtual environment and activate it:

    python -m venv .venv
    source .venv/bin/activate
    
  2. Install this package: pip install londonaicentre-mesa-local.

Usage

CLI (primary)

  1. Note command line arguments:

    Argument Description
    -v, --verbose Enable debug output (optional)
  2. Start the server as follows: mesalocal [args].

Library (secondary)

  1. Import and use the logic of this package as a library:
import asyncio
from mesalocal.weights import Weights
from mesalocal.inferrer import VLLM
vllm_config: VLLMConfig = VLLMConfig() # VLLMConfig(model_name="foo", gpu="bar") to use a vLLM config without a .env file
weights: Weights = Weights(vllm_config.model)
if weights.unpack():
    vllm: VLLM = VLLM(weights.get_model_folder(), vllm_config)
    async def run():
        async for output in vllm.generate(prompt):
            print(output.outputs[0].text)
    asyncio.run(run())

Clients

OpenAI (example with Oncollama)

  1. Interact with the server using the OpenAI client in python:

    from openai import OpenAI
    from oncoschema.prompt_builder import PromptBuilder # pip install londonaicentre-oncoschema
    
    client = OpenAI(
        base_url="http://localhost:5000/v1",
        api_key="blank" 
    )
    
    response = client.chat.completions.create(
        model="oncollama3betav01",
        messages=[
            {"role": "system", "content": PromptBuilder().build_main_prompt()},
            {"role": "user", "content": "Diagnosis 01/01/26..."}
        ]
    )
    
    print(response.choices[0].message.content)
    

License

This project uses a proprietary license (see LICENSE).

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

londonaicentre_mesa_local-2.6.0.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

londonaicentre_mesa_local-2.6.0-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file londonaicentre_mesa_local-2.6.0.tar.gz.

File metadata

  • Download URL: londonaicentre_mesa_local-2.6.0.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Amazon Linux","version":"2023","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for londonaicentre_mesa_local-2.6.0.tar.gz
Algorithm Hash digest
SHA256 cefab079fe7a8b0664ace59f3f4b3d4f742c17ed1f978c62595ab8c80d854b55
MD5 c2b36caacd5186716a3be3cadc9fd73d
BLAKE2b-256 bc56d5243993cd9a0f0c0061b5b88347c0ce8f030b5f8059f5fc4b48f2becb0c

See more details on using hashes here.

File details

Details for the file londonaicentre_mesa_local-2.6.0-py3-none-any.whl.

File metadata

  • Download URL: londonaicentre_mesa_local-2.6.0-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Amazon Linux","version":"2023","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for londonaicentre_mesa_local-2.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d045d209613e87aa6c91c1d27428bb81837211dab4c6a04cec889a75dc16a17a
MD5 710d3e00d01f70cbf8ed10d4b048813a
BLAKE2b-256 49ddfe1f8742cf3c7045b83c72879765a6d9180079f9a72000af7e8ed4cf9c0f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page