โ02-15-2024 08:04 PM - edited โ02-15-2024 08:07 PM
[8586fsbgpb] An error occurred while loading the model. Failed to load the pickled function from a hexadecimal string. Error: Can't get attribute 'transform_input' on <module '__main__' from '/opt/conda/envs/mlflow-env/bin/gunicorn'>.
Iยดm using the function to transform input and output on this way
โ02-16-2024 12:15 PM
The solution I found was to create those functions in a separated python code called eg. custom_functions.py and deploy as follows in ml flow
โ02-16-2024 01:10 AM
Hi @marcelo2108,
The error you're encountering is due to the fact that your transform_input
and transform_output
functions are defined within the script where you're trying to use them. When you're using MLflow with Databricks, it's important to ensure that your functions are defined at the top level of your script, not within other functions or classes. This is because MLflow needs to be able to import your functions, and when they're defined within other functions or classes, they're not available for import.
To fix this issue, you should define your transform_input
and transform_output
functions at the top level of your script.
Here's an example of how you can do this:
def transform_input(**request):
print('Type of prompt',type(request["prompt"]))
request["messages"] = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": request["prompt"]},
]
request["stop"] = ['\n\n']
print("Request format",request)
return request
def transform_output(response):
return response['candidates'][0]
llm = Databricks(endpoint_name='llama2-7b-chat-completion',
transform_input_fn=transform_input,
transform_output_fn=transform_output,extra_params={"temperature":0.01,"max_tokens": 300})
Now, your functions should be available for import by MLflow, and you should no longer encounter the error you were seeing.
โ02-16-2024 04:22 AM
Hi @Kaniz I put already on top level of the cell script, exactly you mentioned as in the attachment file but no look. Should I put on the top of notebook ? Any other clue about ?
โ02-16-2024 12:15 PM
The solution I found was to create those functions in a separated python code called eg. custom_functions.py and deploy as follows in ml flow
โ02-16-2024 12:33 PM
However I could not progress in the end I mean because I found the error I reported in other thread as follows
[5bb99fzs2f] An error occurred while loading the model. You haven't configured the CLI yet! Please configure by entering `/opt/conda/envs/mlflow-env/bin/gunicorn configure`.
As described in :
Re: Problem when serving a langchain model on Data... - Databricks - 59506
Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections.
Click here to register and join today!
Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.