This message was deleted.
# ask-for-help
s
This message was deleted.
c
you should be able to do something like this to run a python script in Jenkins:
Copy code
stage('build') {
    steps {
        sh 'python my_script.py'
    }
}
s
But bentoml build would be required to build a bento after saving bento on disk
c
oh yes,
bentoml build
is a CLI command, you can invoke it directly in shell
after
pip install bentoml
, you should have access to the
bentoml
cli command, try
which bentoml
s
Copy code
+ python3 -c from blob_connection import download_model_files; download_model_files("M156601414")
code1.1 M156601414
M156601414/bentofile.yaml
M156601414/bentoml_store.py
M156601414/deploy.zip
M156601414/diabetes_dt.pkl
M156601414/requirements.txt
M156601414/service.py
Model files downloaded successfully.
[Pipeline] sh
+ python3 bentoml_store.py
/var/lib/jenkins/.local/lib/python3.10/site-packages/sklearn/base.py:318: UserWarning: Trying to unpickle estimator DecisionTreeClassifier from version 1.0.2 when using version 1.2.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
<https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations>
  warnings.warn(
Converting 'Machine_Learning_Model' to lowercase: 'machine_learning_model'.
[Pipeline] sh
+ bentoml list
 Tag  Size  Creation Time  Path
It is not unable to save it to bentoml store on VM.Instead it is creating a vague folder.
c
Could you share the code?
s
import pickle #import xgboost import sklearn import bentoml #Loading model to compare the results model = pickle.load(open('diabetes_dt.pkl','rb')) # Save model bentoml.sklearn.save_model('diabetes_dt',model)
c
Have you checked bentoml models list ?
Since your script only saves the model, not a Bento
s
Copy code
+ python3 bentoml_store.py
/var/lib/jenkins/.local/lib/python3.10/site-packages/sklearn/base.py:318: UserWarning: Trying to unpickle estimator DecisionTreeClassifier from version 1.0.2 when using version 1.2.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
<https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations>
  warnings.warn(
Converting 'Machine_Learning_Model' to lowercase: 'machine_learning_model'.
[Pipeline] sh
+ bentoml models list
 Tag                            Module           Size       Creation Time       
 machine_learning_model:f3qnu…  bentoml.sklearn  16.58 KiB  2023-03-29 16:03:02
It is saving model with a vague name.My bentoml_store.py has different name
c
Oh I see
That’s expected behavior
See the warning message above
s
The problem is that I don't have it saved in Machine_Learning_Model name.It's peculiar why this is happening
c
I see, you expect the name to be diabetes_dt?
That seem weird, are you running any other script in the pipeline?
s
yes..i am connecting it to a blob storage where all my bentoml specific files are stored.
Copy code
+ python3 -c from blob_connection import download_model_files; download_model_files("M156601414")
code1.1 M156601414
M156601414/bentofile.yaml
M156601414/bentoml_store.py
M156601414/deploy.zip
M156601414/diabetes_dt.pkl
M156601414/requirements.txt
M156601414/service.py
Model files downloaded successfully.
[Pipeline] sh
+ python3 bentoml_store.py
/var/lib/jenkins/.local/lib/python3.10/site-packages/sklearn/base.py:318: UserWarning: Trying to unpickle estimator DecisionTreeClassifier from version 1.0.2 when using version 1.2.2. This might lead to breaking code or invalid results. Use at your own risk. For more info please refer to:
<https://scikit-learn.org/stable/model_persistence.html#security-maintainability-limitations>
  warnings.warn(
Converting 'Machine_Learning_Model' to lowercase: 'machine_learning_model'.
[Pipeline] sh
+ bentoml models list
 Tag                            Module           Size       Creation Time       
 machine_learning_model:f3qnu…  bentoml.sklearn  16.58 KiB  2023-03-29 16:03:02
c
What’s in the bento_store.py file?
s
import pickle #import xgboost import sklearn import bentoml #Loading model to compare the results model = pickle.load(open('diabetes_dt.pkl','rb')) # Save model bentoml.sklearn.save_model('diabetes_dt',model)
c
Could it be that you’re downloading an older version of the file? Could you manually check the file in that bucket?
s
I checked that too..uploaded new files too but still it is catching the same issue
c
Do you use any kind of caching mechanism in the download_model_files method?
s
container_name = "upload" def download_model_files(model_id): # Generate the folder name from the model ID print("code1.1",model_id) folder_name = model_id # Initialize the BlobServiceClient blob_service_client = BlobServiceClient.from_connection_string(connection_string) # Get the container client container_client = blob_service_client.get_container_client(container_name) # List blobs in the folder blobs_in_folder = [] for blob in container_client.list_blobs(name_starts_with=folder_name): blobs_in_folder.append(blob.name) #Print the list of blobs in the folder for blob_name in blobs_in_folder: print(blob_name) # Download the blobs to the current folder for blob_name in blobs_in_folder: local_file_name = os.path.basename(blob_name) if not os.path.exists(local_file_name): # Get the blob client blob_client = container_client.get_blob_client(blob_name) # Download the blob to the current folder blob_content = blob_client.download_blob().readall() with open(local_file_name, "wb") as f: f.write(blob_content) print("Model files downloaded successfully.") This is the code i am using to download file from blob
and then defining jenkins pipeline stages
stages { stage('Code Checkout from Repo') { steps { git branch: 'Jenkins_Test', credentialsId: '9fd03f0b-61d8-4a28-b010-734d3f51b3c4', url: 'https://eysbp.visualstudio.com/sda-dna-mlops-accelerator/_git/mlops_accelerator_poc_notebooks' } } stage('Run Python Script') { steps { echo "My model_id is ${params.model_id}" sh "python3 -c 'from blob_connection import download_model_files; download_model_files(\"${params.model_id}\")'" // sh 'pip3 install bentoml' sh 'python3 bentoml_store.py' // sh ' #!/usr/bin/env python import bentoml' sh 'bentoml models list' // sh 'bentoml build' sh 'bentoml containerize diabetes_risk_classifier:latest -t diabetes_risk_classifier:latest' script { env.BUILT_IMAGE_NAME = "diabetes_risk_classifier" env.BUILT_IMAGE_TAG = "latest" env.BUILT_IMAGE_ID = sh(script: "docker images ${env.BUILT_IMAGE_NAME}:${env.BUILT_IMAGE_TAG} -q", returnStdout: true).trim() } } }
Is there any way to remove cache memory from the system so that every build is fresh instead of using from cache?
c
That largely depends on your setup, I don’t think s3 client does this automatically
👍 1