Skip to main content

A dependency-free, code-less socket-based solution for resolving environment incompatibilities

Project description

A dependency-free, code-less socket-based solution for resolving (Python / conda) environment incompatibilities.

Usage Guidelines

Installation:

To install the inincompatibility package, run:

pip install inincompatibility

Example: Making Your LLMs Callable Like an API:

First, make your LLMs (e.g., Llama-3.2-1B) callable functions:

# your_llm.py
import torch
from transformers import pipeline as pl

m = "meta-llama/Llama-3.2-1B"
p = pl("text-generation", model=m, device="cuda")

def llm_qa(msg: list) -> dict:
    return p(msg)[0]["generated_text"]

Next, create another Python file (e.g., to_import_ori.py) to import the LLM function:

# to_import_ori.py
from your_llm import llm_qa

Then, use the inincompatibility CLI to generate the necessary importable code and then run the LLM in its (Python / conda) environment:

conda activate llama
pip install inincompatibility
python -m inincompatibility -i to_import_ori.py -o to_import.py

A file named to_import.py (specified by the -o argument) will be generated as follows:

# Generated by `inincompatibility`.
# **Not** depend on `incompatibility`. :)
# You can directly `import` this file in another environment.
import socket
import pickle

BUFFER_SIZE = 65536

client = socket.socket(2, socket.SOCK_STREAM)
client.connect(('127.0.0.1', 57849))

def _func_eval(func, args, kwargs):
    data = pickle.dumps((func, args, kwargs))
    client.sendall(data)
    return pickle.loads(client.recv(BUFFER_SIZE))

def _inincompatibility_remote_eval(*args, **kwargs):
    return _func_eval('_inincompatibility_remote_eval', args, kwargs)

def _inincompatibility_remote_exec(*args, **kwargs):
    return _func_eval('_inincompatibility_remote_exec', args, kwargs)

def llm_qa(*args, **kwargs):
    return _func_eval('llm_qa', args, kwargs)

Now, you can directly import the generated code in another (Python / conda) environment:

# main.py
from to_import import llm_qa
print(llm_qa('The key to life is'))

Run your main script (e.g., main.py) in the target environment:

conda activate blackbox
python main.py

For more details, check out the sample-llama directory on GitHub.

Example: Additional Samples:

For more usage examples, visit the sample-local directory on GitHub.

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

inincompatibility-0.0.6.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

inincompatibility-0.0.6-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file inincompatibility-0.0.6.tar.gz.

File metadata

  • Download URL: inincompatibility-0.0.6.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for inincompatibility-0.0.6.tar.gz
Algorithm Hash digest
SHA256 1c60493c1fba4c99dccc0c082172febccecdf7bf664e861408be4c2b2e500f6f
MD5 36bb868153c8cccfe3ad6404f3885595
BLAKE2b-256 5639da3b3a0361cd4264e3393770b8f5bb23fba93d706d45f4bab4f5a176e880

See more details on using hashes here.

File details

Details for the file inincompatibility-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for inincompatibility-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7d01da99758ece2860a50086a97d260ed5876b8e8a5c87ef788e04d6d252095a
MD5 04671f17aebaf0292ee68cb3d3556246
BLAKE2b-256 8bd06df3ad8a61e15dc5584f3393fbe7affdbd6c36212e281e8a57c8a82f1320

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