microsoft / genaiops-promptflow-template

GenAIOps with Prompt Flow is a "GenAIOps template and guidance" to help you build LLM-infused apps using Prompt Flow. It offers a range of features including Centralized Code Hosting, Lifecycle Management, Variant and Hyperparameter Experimentation, A/B Deployment, reporting for all runs and experiments and so on.
Other
271 stars 238 forks source link

How do I use a different python version for prompt flow custom runtime? #154

Open sparse-coder opened 5 months ago

sparse-coder commented 5 months ago

We are using our own environment definition to build the promptflow runtime image, and use it as the base for provisioning the custom runtime on AML compute instance for doing batch and evaluation runs.

So far we are good.

What we need is a way to use a different python version e.g. Python 3.11 on my custom runtime. Is there a way I can do this? So far what I have observed is all the base images supplied by mcr use python 3.9.

My docker file looks like this FROM mcr.microsoft.com/azureml/promptflow/promptflow-runtime-stable:20240515.v1 COPY ./* ./ RUN pip install -r requirements.txt Is there a way I can define something in my docker file to upgrade the python version?

stewartadam commented 4 months ago

We're looking to do something similar, you can use conda to update the runtime env with conda install -y 'python=3.11' but unfortunately unseats the promptflow-runtime whl and since that wheel is unpublished, you can't get it back from upstream. You have to manually copy it between Python versions:

FROM mcr.microsoft.com/azureml/promptflow/promptflow-runtime:latest

# Update to Python 3.11
RUN conda install -y 'python=3.11' -p /azureml-envs/prompt-flow/runtime && \
  pip install --no-cache-dir -r extra_requirements.txt && \

# Copy Python 3.9 promptflow-runtime whl to 3.11
RUN cp -a azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow/runtime azureml-envs/prompt-flow/runtime/lib/python3.11/site-packages/promptflow/ && \
  sed -i -e 's|bin/python3.9|bin/python3.11|' /azureml-envs/prompt-flow/runtime/bin/prt && \
  grep ^Requires-Dist azureml-envs/prompt-flow/runtime/lib/python3.9/site-packages/promptflow_runtime-*.dist-info/METADATA | cut -d' ' -f2- | cut -d';' -f1 > promptflow-runtime-requirements.txt && \
  pip install --no-cache-dir -r promptflow-runtime-requirements.txt

It's ugly and probably prone to breakage so YMMV, but it works with the current image. If you want to investigate further, this is what helped me:

# pseudo-generate the original dockerfile instructions
docker history --no-trunc --format json mcr.microsoft.com/azureml/promptflow/promptflow-runtime | jq -r '.CreatedBy' | tac

# start the runtime img to inspect its dependencies
docker run -it --rm --entrypoint /bin/bash mcr.microsoft.com/azureml/promptflow/promptflow-runtime:latest /bin/bash
pip show -f promptflow-runtime
sparse-coder commented 4 months ago

@stewartadam Thank you! I did the same thing by updating the conda env, but this idea of copying the promptflow-runtime wheel didn't occur to me. Good idea👍 BTW!

For now we have decided to not go through this route!

Thank you!

ebotiab commented 1 month ago

Hi, is this issue expected to be fixed in the future?

WilliamWatsonEAI commented 3 weeks ago

@ebotiab agreed, this should not be so hard to change base image Python version