-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PF in aml pipeline - github actions/azdo pipelines (#145)
Code for Promptflow as a component in AML pipeline --------- Co-authored-by: Sugandh Mishra (HE/HIM) <[email protected]> Co-authored-by: PRIYA BHIMJYANI <[email protected]> Co-authored-by: priya-27 <[email protected]>
- Loading branch information
1 parent
e1e6dbd
commit e327973
Showing
8 changed files
with
431 additions
and
5 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
.azure-pipelines/web_classification_pf_in_aml_pipeline_workflow.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
parameters: | ||
- name: env_name | ||
displayName: "Execution Environment" | ||
default: "dev" | ||
- name: use_case_base_path | ||
displayName: "Base path of model to execute" | ||
default: "web_classification" | ||
|
||
stages: | ||
- stage: execute_training_job | ||
displayName: execute_training_job | ||
jobs: | ||
- job: Execute_ml_Job_Pipeline | ||
steps: | ||
- template: templates/get_connection_details.yml | ||
|
||
- template: templates/configure_azureml_agent.yml | ||
|
||
- template: templates/execute_python_code.yml | ||
parameters: | ||
step_name: "Execute PF IN AML Pipeline" | ||
script_parameter: | | ||
python -m pf_aml_pipeline.promptflow_in_aml_pipeline \ | ||
--subscription_id "$(SUBSCRIPTION_ID)" \ | ||
--env_name ${{ parameters.env_name }} \ | ||
--base_path ${{ parameters.use_case_base_path }} |
61 changes: 61 additions & 0 deletions
61
.github/workflows/web_classification_pf_in_aml_pipeline_workflow.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: web_classification_pf_in_aml_pipeline_workflow.yml | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
env_name: | ||
type: string | ||
description: "Execution Environment" | ||
required: true | ||
default: "dev" | ||
use_case_base_path: | ||
type: string | ||
description: "The base path of the flow use-case to execute" | ||
required: true | ||
default: "web_classification" | ||
secrets: | ||
azure_credentials: | ||
description: "service principal authentication to Azure" | ||
required: true | ||
jobs: | ||
flow-experiment-and_evaluation: | ||
name: prompt flow experiment and evaluation job in Azure ML | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: ${{ inputs.env_name }} | ||
env: | ||
RESOURCE_GROUP_NAME: ${{ vars.RESOURCE_GROUP_NAME }} | ||
WORKSPACE_NAME: ${{ vars.WORKSPACE_NAME }} | ||
COMPUTE_TARGET: ${{ vars.COMPUTE_TARGET }} | ||
steps: | ||
- name: Checkout Actions | ||
uses: actions/checkout@v4 | ||
|
||
- name: Azure login | ||
uses: azure/login@v1 | ||
with: | ||
creds: ${{ secrets.azure_credentials }} | ||
|
||
- name: Configure Azure ML Agent | ||
uses: ./.github/actions/configure_azureml_agent | ||
|
||
- name: load the current Azure subscription details | ||
id: subscription_details | ||
shell: bash | ||
run: | | ||
export subscriptionId=$(az account show --query id -o tsv) | ||
echo "SUBSCRIPTION_ID=$subscriptionId" >> $GITHUB_OUTPUT | ||
#===================================== | ||
# Run Promptflow in AML Pipeline | ||
#===================================== | ||
- name: Run Promptflow in AML Pipeline | ||
uses: ./.github/actions/execute_script | ||
with: | ||
step_name: "Run Promptflow in AML Pipeline" | ||
script_parameter: | | ||
python -m pf_aml_pipeline.promptflow_in_aml_pipeline \ | ||
--subscription_id ${{ steps.subscription_details.outputs.SUBSCRIPTION_ID }} \ | ||
--env_name ${{ inputs.env_name || 'dev' }} \ | ||
--base_path ${{ inputs.use_case_base_path || 'web_classification'}} \ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import argparse | ||
|
||
import pandas as pd | ||
from pathlib import Path | ||
|
||
PF_OUTPUT_FILE_NAME = "parallel_run_step.jsonl" | ||
def parse_args(): | ||
""" | ||
Parses the user arguments. | ||
Returns: | ||
argparse.Namespace: The parsed user arguments. | ||
""" | ||
parser = argparse.ArgumentParser( | ||
allow_abbrev=False, description="parse user arguments" | ||
) | ||
parser.add_argument("--input_data_path", type=str) | ||
|
||
args, _ = parser.parse_known_args() | ||
return args | ||
|
||
|
||
def main(): | ||
""" | ||
The main function that orchestrates the data preparation process. | ||
""" | ||
args = parse_args() | ||
|
||
# Read promptflow output file and do some postprocessing | ||
input_data_path = args.input_data_path + '/' + PF_OUTPUT_FILE_NAME | ||
with open((Path(input_data_path)), 'r') as file: | ||
promptflow_output = pd.read_json(file, lines=True) | ||
print(promptflow_output.head()) | ||
|
||
return | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import argparse | ||
|
||
import pandas as pd | ||
|
||
|
||
def parse_args(): | ||
""" | ||
Parses the user arguments. | ||
Returns: | ||
argparse.Namespace: The parsed user arguments. | ||
""" | ||
parser = argparse.ArgumentParser( | ||
allow_abbrev=False, description="parse user arguments" | ||
) | ||
parser.add_argument("--max_records", type=int, default=1) | ||
parser.add_argument("--input_data_path", type=str) | ||
parser.add_argument("--output_data_path", type=str) | ||
|
||
args, _ = parser.parse_known_args() | ||
return args | ||
|
||
|
||
def main(): | ||
""" | ||
The main function that orchestrates the data preparation process. | ||
""" | ||
args = parse_args() | ||
print("Maximum records to keep", args.max_records) | ||
|
||
input_data_path = args.input_data_path | ||
input_data_df = pd.read_json(input_data_path, lines=True) | ||
|
||
# take only max_records from input_data_df | ||
input_data_df = input_data_df.head(args.max_records) | ||
|
||
# Write input_data_df to a jsonl file | ||
input_data_df.to_json( | ||
args.output_data_path, orient="records", lines=True | ||
) | ||
print("Successfully written filtered data") | ||
|
||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.