Skip to main content

Prompt Execution Path Selection in Retrieval-Based LLM Inference Systems

Project description

PromptPlanner

Install

Python >=3.10

git clone https://github.com/SecretSettler/PromptPlanner.git
cd PromptPlanner
pip install -e .

Data Format:

Currently we only support data with jsonl format. Each json should at least contain these attributes:

{
    "qid": 0,
    "text": "Is the sky blue?",
    "answer": ["Yes", "Yes the sky is blue"],
    "top_k_doc_id": [2, 8, 1, 10]
}

Quick usage

from promptplanner.offline.clustering import cluster_prompts
from promptplanner.offline.inter_reordering import PromptProcessor
import json
import argparse

def parse_args():
    parser = argparse.ArgumentParser(description="Reorder prompt data based on clustering results.")
    parser.add_argument('--prompt_path', type=str, required=True, help='Path to the JSONL file containing prompt data.')
    return parser.parse_args()

def main():
    args = parse_args()
    
    # Load prompts from the specified path
    prompt_path = args.prompt_path
    with open(prompt_path, 'r') as f:
        prompts = [json.loads(line) for line in f]

    qids = [prompt['qid'] for prompt in prompts]
    questions = [prompt['text'] for prompt in prompts]
    answers = [prompt['answer'] for prompt in prompts]
    topk_doc_ids = [prompt['top_k_doc_id'] for prompt in prompts]


    processer = PromptProcessor(use_gpu=True)
    # Perform clustering (Intra-reordering)
    result = cluster_prompts(topk_doc_ids, similarity_method="sharp", use_triton=True)
    # Perform inter-reordering
    organized_reordered_ids, _, final_index_mapping = processer.process_and_reorder(result.reordered_prompts, topk_doc_ids, show_progress=True)

    # Results
    reorded_qids = [qids[i] for i in final_index_mapping]
    reorded_questions = [questions[i] for i in final_index_mapping]
    reorded_answers = [answers[i] for i in final_index_mapping]
    reorded_topk_doc_ids = organized_reordered_ids
    return reorded_qids, reorded_questions, reorded_answers, reorded_topk_doc_ids

if __name__ == "__main__":
    reorded_qids, reorded_questions, reorded_answers, reorded_topk_doc_ids = main()

The example code is in examples/planner/example.py

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

promptplanner-0.0.1.tar.gz (33.5 kB view details)

Uploaded Source

Built Distribution

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

promptplanner-0.0.1-py3-none-any.whl (38.5 kB view details)

Uploaded Python 3

File details

Details for the file promptplanner-0.0.1.tar.gz.

File metadata

  • Download URL: promptplanner-0.0.1.tar.gz
  • Upload date:
  • Size: 33.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for promptplanner-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b7fb11e8af839ce8a3a1da87e5e0545d2f62018a82f302cec2394fe338daf4b1
MD5 4df15c8231643ddd73486405ddfaf90c
BLAKE2b-256 57ec8c98ceb8af36d6de0dcebaf0e5268320071160864daac1df0d1ebc6b510b

See more details on using hashes here.

File details

Details for the file promptplanner-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: promptplanner-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 38.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for promptplanner-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64a8bf755aa135384e1fe05ec3bbe72841f1ceba87a8b9baa83851efbbebe5d8
MD5 c3a40138eb1b0f7c4790341af9cad421
BLAKE2b-256 b7b2bc0f8f2c4d7e792c2dd2ae34989a688c0dc0a0105971dbfe6601acbd2ea4

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