How We Improved Engineers’ Productivity in ML Training Pipeline

Published Sep 03 2021 09:30 AM 832 Views
Microsoft

If you’re working with Azure CLI and Azure PowerShell, chances are that you’re using one of our AI-powered features for Azure Cli and Az Predictor for Azure PowerShell. We build and improve our own services to serve the models. Behind the scenes, we created and improved the training pipeline that generates the model. In this blog post we will explain the challenges regarding our own engineers’ productivity and how we improved the training pipeline to make it easier and faster for us to iterate the training pipeline.

 

The Training Pipeline 1.0

We iterated quickly to create our model and moved our training pipeline from prototype to production. Just like any basic training pipeline, we made our initial pipeline two major components: 1) a Data Extractor for collecting various data sets required for our models; 2) a Model Generator for training and generating a model. Due to time constraints, we also included all the logic for validating and deploying our models in various service end points in the Model Generator component, as well as the logic to enhance Azure CLI and Azure PowerShell documentations.

 

The Challenges

We focused on making our pipeline 1.0 in production and it accomplished our goals of creating our AI model in production. But we experienced a few pain points in engineering productivity area when we continued iterating our pipeline with bug fixes and new features. There are some cases we want to react quickly. First, there are rapid changes including breaking changes in Azure CLI and Azure PowerShell. Some changes affect how we extract the data sets. Some changes affect how we train the model. Second, we want to respond quickly and properly to customer requests and feedback and update our models and the service. Third, we want to expand our pipeline and do some experiments for new scenarios. The pipeline 1.0 is good for production, but it’s too inefficient to test, reuse and validate a change. As we mentioned earlier, there were only two separate components in pipeline 1.0. The Model Generator component included too many different logic and purposes. It became the bottleneck that stopped us from developing and iterating quickly. For example, if I found a bug in the logic that updated Azure PowerShell documentation, I had to run the whole Model Generator component to verify my fix. Since Model Generator component included too many logics, most of that weren’t necessary for updating Azure PowerShell documentation. For example, I couldn’t reuse the existing model for updating Azure PowerShell documentation. Model Generator always generated a new one. It led to a lot of wasted time and much slower productivity.

 

The Training Pipeline 2.0

To overcome the issues that surfaced in pipeline 1.0, we started to work on pipeline 2.0. The main goal was to improve engineering productivity. We decided that

  1. The data and models need versioning.
  2. It is important to have smaller modules in the pipeline for testing, reusing, and validation.
  3. The runtime performance is important for both production and development.

We made three major changes to our pipeline:

  1. Used Azure Data Factory, Azure Batch, and an in-house inventory system.
  2. Modularized our training pipeline.
  3. Improved runtime performance.

Using Azure Data Factory, Azure Batch, and an in-house Inventory System

We worked on a generic training platform that focused on facilitating fast experimenting and production.

 

The generic training platform uses Azure Data Factory (ADF) to orchestrate the data movement and to transform the data at scale. We use custom activities in Azure Data Factory to move and transform the data. A custom activity runs the code in an Azure Batch pool of virtual machines. The data is stored in Azure Storage.

 

On top of it, we created an in-house Inventory system that provides versioning, description, and retention support of the data. Retrieving and storing the data is done via the Inventory system.

 

The generic training platform also provides a useful command line interface to easily create an activity that comes with authentication and logging already set up, so we just focus on the business logic. We also can integrate what the generic training platform provides in CI/CD to deploy the code to production.

 

Given the benefits of the generic training platform, we built our pipeline 2.0 on top of it. As shown in the diagram below, there are more than one activity. When an activity runs, the code runs in an Azure Batch pool. We serve the Inventory System in an Azure Web App. When we need to get the data from the Inventory system, we send a request with the version we want to Inventory System. The response includes how to download it from Azure Storage. Then we download the data from the storage account.

ADF diagram.png

Modularizing our Training Pipeline

To convert our monolithic Model Generator component into smaller modules, we followed the data and analyzed what data we needed and what data we generated. We found that the component could be divided into smaller modules:

  1. Generate New Help: This generates the help table for all the commands. Basically, this is the “--help” for all Azure CLI commands or “get-help” for all Azure PowerShell commands. We use this information to verify whether the new example is valid or not.
  2. Generate KB (knowledge base): This generates the new model. The model is a knowledge base of new examples.
  3. Release: After we have the new model, we need to publish it to the service.
  4. Create PR (pull request): After we have the new model, we would like to enhance the existing Azure CLI and Azure PowerShell documentation with the new examples. This is done via a pull request to the corresponding GitHub repository.

Each of them, including the crawler, is a custom activity in the final ADF pipeline.  

 

In the end, we chain all these activities into the final pipeline. We also have flags to skip some activities. The benefit of this approach is that we do not always need to run everything together.  So, a small change in one section of the pipeline does not require the whole pipeline to be run again. For example, validating how we update documentation only requires us to run the Create PR activity and not the others.

 

Reuse the Output from Each Small Module

Since we broke down the monoliths into smaller modules, it required us to store the output from each module and share that with the ones that take the data as input. As mentioned before, we used the in-house Inventory system. With the versioning support from the Inventory system, it was easier to restart a particular activity in the pipeline or reproduce an issue on a different machine. All we need to do is to set up the type of data and version to use for that activity. For example, when I need to debug an issue in Create PR activity, I can specify the version of the KB. I don’t worry that the input may be different when I run the activity at different time.

 

Improving the Runtime Performance

To make testing and debugging the pipeline more efficient, we also improved the code performance.

 

Run the Pipeline in Parallel

We used to do everything one after another. We ran the crawler first, then we generated the help table, generated the new model, updated the service using the new model, and created pull request to add examples back to documentation. While we analyzed the data flow, we figured out there were not always strict dependencies in that sequence order. For example, we didn’t need anything from the crawler to generate the help table. Using Azure Data Factory, we moved some computing to run in parallel.

 

Eventually we had a pipeline to chain all those activities together and ran some of them in parallel. As shown in the diagram below, each of the "If Condition" activity is triggering a custom activity. The Crawler activity is run in parallel with the Generate New Help activity. The Release activity is run in parallel with the Create PR activity. Each of those has the "If condition" we can set when we start this pipeline. That makes it more flexible for us to decide what to run when we trigger a pipeline.

 

Maoliang_0-1630604135440.png

 

 

Run the Code in Parallel

We started writing the program single threaded for simplicity and correctness. Once that was done, there were a few patterns in the code that we could easily convert to multi-threaded. Take the crawler for example. What it does is to download the repositories, go through each relevant file, and extract the information. If you spot the patterns here, you’ll figure out how we convert it to multi-threaded. For each repository, we need to download it and parse files in it. And for each file in that repository, we need to parse and extract the information. Each of those operations doesn’t affect the others. Downloading a repository doesn’t affect extracting information from other repositories. Parsing a file doesn’t affect the other files. Those are good candidates for parallelism. We don’t manage threading directly ourselves. We use Parallel.ForEach and ParallelForEachExtensions.ParallelForEachAsync. Each allows us to configure maximum degree of parallelism. With that we can set the maximum degree of parallelism to 1 when we debug the code. In the pipeline, we just use the default setting for the maximum degree of parallelism.

 

After we converted it to multi-threaded, it takes about 13 minutes in a typical run. While it took 16 minutes single threaded. There is about 18% improvement in the runtime.

 

Development on Local Machines

We used our Inventory system to store the data for re-use between smaller modules as well as between the runs on different local machines. All data is stored and shared in the Inventory system. This allows us to easily share data between machines. For example, when I am debugging an issue in an activity, I can ask my co-worker to help investigate, without the need to directly give them the input data. I just need to give them a reference to the version of the data used. My co-worker can then use this reference to reproduce the issue on their local machine, without having to run the activities that generated the input data to begin with. No process needs to be duplicated; we just need to focus on the activity being debugged.

 

We've come a long way from the first version we implemented. We have since then improved our pipeline’s performance and our engineering productivity.  With those changes, we were able to reduce the time to run the whole pipeline from 8 to 1.5 hours. Our engineering productivity also improved by not having to run the whole pipeline just to verify our changes. But we’re not stopping here. There is still room to improve regarding performance and productivity. As we continue our journey in building AI model pipelines and services, we will share our learning with you.

%3CLINGO-SUB%20id%3D%22lingo-sub-2712409%22%20slang%3D%22en-US%22%3EHow%20We%20Improved%20Engineers%E2%80%99%20Productivity%20in%20ML%20Training%20Pipeline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2712409%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you%E2%80%99re%20working%20with%20Azure%20CLI%20and%20Azure%20PowerShell%2C%20chances%20are%20that%20you%E2%80%99re%20using%20one%20of%20our%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-tools%2Fempowering-azure-cli-developers-with-ai%2Fba-p%2F1701251%22%20target%3D%22_blank%22%3EAI-powered%20features%3C%2FA%3E%20for%20Azure%20Cli%20and%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-tools%2Fannouncing-az-predictor-preview-3%2Fba-p%2F2197744%22%20target%3D%22_blank%22%3EAz%20Predictor%3C%2FA%3E%20for%20Azure%20PowerShell.%20We%20build%20and%20improve%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-tools%2Fai-powered-azure-tools%2Fba-p%2F2080799%22%20target%3D%22_blank%22%3Eour%20own%20services%3C%2FA%3E%20to%20serve%20the%20models.%20Behind%20the%20scenes%2C%20we%20created%20and%20improved%20the%20training%20pipeline%20that%20generates%20the%20model.%20In%20this%20blog%20post%20we%20will%20explain%20the%20challenges%20regarding%20our%20own%20engineers%E2%80%99%20productivity%20and%20how%20we%20improved%20the%20training%20pipeline%20to%20make%20it%20easier%20and%20faster%20for%20us%20to%20iterate%20the%20training%20pipeline.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--356200841%22%20id%3D%22toc-hId--356047800%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-2131311992%22%20id%3D%22toc-hId-2131465033%22%3EThe%20Training%20Pipeline%201.0%3C%2FH2%3E%0A%3CP%3EWe%20iterated%20quickly%20to%20create%20our%20model%20and%20moved%20our%20training%20pipeline%20from%20prototype%20to%20production.%20Just%20like%20any%20basic%20training%20pipeline%2C%20we%20made%20our%20initial%20pipeline%20two%20major%20components%3A%201)%20a%20Data%20Extractor%20for%20collecting%20various%20data%20sets%20required%20for%20our%20models%3B%202)%20a%20Model%20Generator%20for%20training%20and%20generating%20a%20model.%20Due%20to%20time%20constraints%2C%20we%20also%20included%20all%20the%20logic%20for%20validating%20and%20deploying%20our%20models%20in%20various%20service%20end%20points%20in%20the%20Model%20Generator%20component%2C%20as%20well%20as%20the%20logic%20to%20enhance%20Azure%20CLI%20and%20Azure%20PowerShell%20documentations.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-323857529%22%20id%3D%22toc-hId-324010570%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--1483596934%22%20id%3D%22toc-hId--1483443893%22%3EThe%20Challenges%3C%2FH2%3E%0A%3CP%3EWe%20focused%20on%20making%20our%20pipeline%201.0%20in%20production%20and%20it%20accomplished%20our%20goals%20of%20creating%20our%20AI%20model%20in%20production.%20But%20we%20experienced%20a%20few%20pain%20points%20in%20engineering%20productivity%20area%20when%20we%20continued%20iterating%20our%20pipeline%20with%20bug%20fixes%20and%20new%20features.%20There%20are%20some%20cases%20we%20want%20to%20react%20quickly.%20First%2C%20there%20are%20rapid%20changes%20including%20breaking%20changes%20in%20Azure%20CLI%20and%20Azure%20PowerShell.%20Some%20changes%20affect%20how%20we%20extract%20the%20data%20sets.%20Some%20changes%20affect%20how%20we%20train%20the%20model.%20Second%2C%20we%20want%20to%20respond%20quickly%20and%20properly%20to%20customer%20requests%20and%20feedback%20and%20update%20our%20models%20and%20the%20service.%20Third%2C%20we%20want%20to%20expand%20our%20pipeline%20and%20do%20some%20experiments%20for%20new%20scenarios.%20The%20pipeline%201.0%20is%20good%20for%20production%2C%20but%20it%E2%80%99s%20too%20inefficient%20to%20test%2C%20reuse%20and%20validate%20a%20change.%20As%20we%20mentioned%20earlier%2C%20there%20were%20only%20two%20separate%20components%20in%20pipeline%201.0.%20The%20Model%20Generator%20component%20included%20too%20many%20different%20logic%20and%20purposes.%20It%20became%20the%20bottleneck%20that%20stopped%20us%20from%20developing%20and%20iterating%20quickly.%20For%20example%2C%20if%20I%20found%20a%20bug%20in%20the%20logic%20that%20updated%20Azure%20PowerShell%20documentation%2C%20I%20had%20to%20run%20the%20whole%20Model%20Generator%20component%20to%20verify%20my%20fix.%20Since%20Model%20Generator%20component%20included%20too%20many%20logics%2C%20most%20of%20that%20weren%E2%80%99t%20necessary%20for%20updating%20Azure%20PowerShell%20documentation.%20For%20example%2C%20I%20couldn%E2%80%99t%20reuse%20the%20existing%20model%20for%20updating%20Azure%20PowerShell%20documentation.%20Model%20Generator%20always%20generated%20a%20new%20one.%20It%20led%20to%20a%20lot%20of%20wasted%20time%20and%20much%20slower%20productivity.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1003915899%22%20id%3D%22toc-hId-1004068940%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--803538564%22%20id%3D%22toc-hId--803385523%22%3EThe%20Training%20Pipeline%202.0%3C%2FH2%3E%0A%3CP%3ETo%20overcome%20the%20issues%20that%20surfaced%20in%20pipeline%201.0%2C%20we%20started%20to%20work%20on%20pipeline%202.0.%20The%20main%20goal%20was%20to%20improve%20engineering%20productivity.%20We%20decided%20that%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EThe%20data%20and%20models%20need%20versioning.%3C%2FLI%3E%0A%3CLI%3EIt%20is%20important%20to%20have%20smaller%20modules%20in%20the%20pipeline%20for%20testing%2C%20reusing%2C%20and%20validation.%3C%2FLI%3E%0A%3CLI%3EThe%20runtime%20performance%20is%20important%20for%20both%20production%20and%20development.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EWe%20made%20three%20major%20changes%20to%20our%20pipeline%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EUsed%20Azure%20Data%20Factory%2C%20Azure%20Batch%2C%20and%20an%20in-house%20inventory%20system.%3C%2FLI%3E%0A%3CLI%3EModularized%20our%20training%20pipeline.%3C%2FLI%3E%0A%3CLI%3EImproved%20runtime%20performance.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId-1683974269%22%20id%3D%22toc-hId-1684127310%22%3EUsing%20Azure%20Data%20Factory%2C%20Azure%20Batch%2C%20and%20an%20in-house%20Inventory%20System%3C%2FH2%3E%0A%3CP%3EWe%20worked%20on%20a%20generic%20training%20platform%20that%20focused%20on%20facilitating%20fast%20experimenting%20and%20production.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20generic%20training%20platform%20uses%20Azure%20Data%20Factory%20(ADF)%20to%20orchestrate%20the%20data%20movement%20and%20to%20transform%20the%20data%20at%20scale.%20We%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-factory%2Ftransform-data-using-dotnet-custom-activity%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ecustom%20activities%3C%2FA%3E%20in%20Azure%20Data%20Factory%20to%20move%20and%20transform%20the%20data.%20A%20custom%20activity%20runs%20the%20code%20in%20an%20Azure%20Batch%20pool%20of%20virtual%20machines.%20The%20data%20is%20stored%20in%20Azure%20Storage.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOn%20top%20of%20it%2C%20we%20created%20an%20in-house%20Inventory%20system%20that%20provides%20versioning%2C%20description%2C%20and%20retention%20support%20of%20the%20data.%20Retrieving%20and%20storing%20the%20data%20is%20done%20via%20the%20Inventory%20system.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20generic%20training%20platform%20also%20provides%20a%20useful%20command%20line%20interface%20to%20easily%20create%20an%20activity%20that%20comes%20with%20authentication%20and%20logging%20already%20set%20up%2C%20so%20we%20just%20focus%20on%20the%20business%20logic.%20We%20also%20can%20integrate%20what%20the%20generic%20training%20platform%20provides%20in%20CI%2FCD%20to%20deploy%20the%20code%20to%20production.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGiven%20the%20benefits%20of%20the%20generic%20training%20platform%2C%20we%20built%20our%20pipeline%202.0%20on%20top%20of%20it.%20As%20shown%20in%20the%20diagram%20below%2C%20there%20are%20more%20than%20one%20activity.%20When%20an%20activity%20runs%2C%20the%20code%20runs%20in%20an%20Azure%20Batch%20pool.%20We%20serve%20the%20Inventory%20System%20in%20an%20Azure%20Web%20App.%20When%20we%20need%20to%20get%20the%20data%20from%20the%20Inventory%20system%2C%20we%20send%20a%20request%20with%20the%20version%20we%20want%20to%20Inventory%20System.%20The%20response%20includes%20how%20to%20download%20it%20from%20Azure%20Storage.%20Then%20we%20download%20the%20data%20from%20the%20storage%20account.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22ADF%20diagram.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307811i302D46CBC12FF776%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22ADF%20diagram.png%22%20alt%3D%22ADF%20diagram.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--123480194%22%20id%3D%22toc-hId--123327153%22%3EModularizing%20our%20Training%20Pipeline%3C%2FH2%3E%0A%3CP%3ETo%20convert%20our%20monolithic%20Model%20Generator%20component%20into%20smaller%20modules%2C%20we%20followed%20the%20data%20and%20analyzed%20what%20data%20we%20needed%20and%20what%20data%20we%20generated.%20We%20found%20that%20the%20component%20could%20be%20divided%20into%20smaller%20modules%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EGenerate%20New%20Help%3A%20This%20generates%20the%20help%20table%20for%20all%20the%20commands.%20Basically%2C%20this%20is%20the%20%E2%80%9C--help%E2%80%9D%20for%20all%20Azure%20CLI%20commands%20or%20%E2%80%9Cget-help%E2%80%9D%20for%20all%20Azure%20PowerShell%20commands.%20We%20use%20this%20information%20to%20verify%20whether%20the%20new%20example%20is%20valid%20or%20not.%3C%2FLI%3E%0A%3CLI%3EGenerate%20KB%20(knowledge%20base)%3A%20This%20generates%20the%20new%20model.%20The%20model%20is%20a%20knowledge%20base%20of%20new%20examples.%3C%2FLI%3E%0A%3CLI%3ERelease%3A%20After%20we%20have%20the%20new%20model%2C%20we%20need%20to%20publish%20it%20to%20the%20service.%3C%2FLI%3E%0A%3CLI%3ECreate%20PR%20(pull%20request)%3A%20After%20we%20have%20the%20new%20model%2C%20we%20would%20like%20to%20enhance%20the%20existing%20Azure%20CLI%20and%20Azure%20PowerShell%20documentation%20with%20the%20new%20examples.%20This%20is%20done%20via%20a%20pull%20request%20to%20the%20corresponding%20GitHub%20repository.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EEach%20of%20them%2C%20including%20the%20crawler%2C%20is%20a%20custom%20activity%20in%20the%20final%20ADF%20pipeline.%20%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20end%2C%20we%20chain%20all%20these%20activities%20into%20the%20final%20pipeline.%20We%20also%20have%20flags%20to%20skip%20some%20activities.%20The%20benefit%20of%20this%20approach%20is%20that%20we%20do%20not%20always%20need%20to%20run%20everything%20together.%20%26nbsp%3BSo%2C%20a%20small%20change%20in%20one%20section%20of%20the%20pipeline%20does%20not%20require%20the%20whole%20pipeline%20to%20be%20run%20again.%20For%20example%2C%20validating%20how%20we%20update%20documentation%20only%20requires%20us%20to%20run%20the%20Create%20PR%20activity%20and%20not%20the%20others.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-567081280%22%20id%3D%22toc-hId-567234321%22%3EReuse%20the%20Output%20from%20Each%20Small%20Module%3C%2FH3%3E%0A%3CP%3ESince%20we%20broke%20down%20the%20monoliths%20into%20smaller%20modules%2C%20it%20required%20us%20to%20store%20the%20output%20from%20each%20module%20and%20share%20that%20with%20the%20ones%20that%20take%20the%20data%20as%20input.%20As%20mentioned%20before%2C%20we%20used%20the%20in-house%20Inventory%20system.%20With%20the%20versioning%20support%20from%20the%20Inventory%20system%2C%20it%20was%20easier%20to%20restart%20a%20particular%20activity%20in%20the%20pipeline%20or%20reproduce%20an%20issue%20on%20a%20different%20machine.%20All%20we%20need%20to%20do%20is%20to%20set%20up%20the%20type%20of%20data%20and%20version%20to%20use%20for%20that%20activity.%20For%20example%2C%20when%20I%20need%20to%20debug%20an%20issue%20in%20Create%20PR%20activity%2C%20I%20can%20specify%20the%20version%20of%20the%20KB.%20I%20don%E2%80%99t%20worry%20that%20the%20input%20may%20be%20different%20when%20I%20run%20the%20activity%20at%20different%20time.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1240373183%22%20id%3D%22toc-hId--1240220142%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-551976171%22%20id%3D%22toc-hId-552129212%22%3EImproving%20the%20Runtime%20Performance%3C%2FH3%3E%0A%3CP%3ETo%20make%20testing%20and%20debugging%20the%20pipeline%20more%20efficient%2C%20we%20also%20improved%20the%20code%20performance.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1255478292%22%20id%3D%22toc-hId--1255325251%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-1232034541%22%20id%3D%22toc-hId-1232187582%22%3ERun%20the%20Pipeline%20in%20Parallel%3C%2FH3%3E%0A%3CP%3EWe%20used%20to%20do%20everything%20one%20after%20another.%20We%20ran%20the%20crawler%20first%2C%20then%20we%20generated%20the%20help%20table%2C%20generated%20the%20new%20model%2C%20updated%20the%20service%20using%20the%20new%20model%2C%20and%20created%20pull%20request%20to%20add%20examples%20back%20to%20documentation.%20While%20we%20analyzed%20the%20data%20flow%2C%20we%20figured%20out%20there%20were%20not%20always%20strict%20dependencies%20in%20that%20sequence%20order.%20For%20example%2C%20we%20didn%E2%80%99t%20need%20anything%20from%20the%20crawler%20to%20generate%20the%20help%20table.%20Using%20Azure%20Data%20Factory%2C%20we%20moved%20some%20computing%20to%20run%20in%20parallel.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEventually%20we%20had%20a%20pipeline%20to%20chain%20all%20those%20activities%20together%20and%20ran%20some%20of%20them%20in%20parallel.%20As%20shown%20in%20the%20diagram%20below%2C%20each%20of%20the%20%22If%20Condition%22%20activity%20is%20triggering%20a%20custom%20activity.%20The%20Crawler%20activity%20is%20run%20in%20parallel%20with%20the%20Generate%20New%20Help%20activity.%20The%20Release%20activity%20is%20run%20in%20parallel%20with%20the%20Create%20PR%20activity.%20Each%20of%20those%20has%20the%20%22If%20condition%22%20we%20can%20set%20when%20we%20start%20this%20pipeline.%20That%20makes%20it%20more%20flexible%20for%20us%20to%20decide%20what%20to%20run%20when%20we%20trigger%20a%20pipeline.%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorMaoliang_3%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22Maoliang_0-1630604135440.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307671i307C7E4646D234AD%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Maoliang_0-1630604135440.png%22%20alt%3D%22Maoliang_0-1630604135440.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--575419922%22%20id%3D%22toc-hId--575266881%22%3ERun%20the%20Code%20in%20Parallel%3C%2FH3%3E%0A%3CP%3EWe%20started%20writing%20the%20program%20single%20threaded%20for%20simplicity%20and%20correctness.%20Once%20that%20was%20done%2C%20there%20were%20a%20few%20patterns%20in%20the%20code%20that%20we%20could%20easily%20convert%20to%20multi-threaded.%20Take%20the%20crawler%20for%20example.%20What%20it%20does%20is%20to%20download%20the%20repositories%2C%20go%20through%20each%20relevant%20file%2C%20and%20extract%20the%20information.%20If%20you%20spot%20the%20patterns%20here%2C%20you%E2%80%99ll%20figure%20out%20how%20we%20convert%20it%20to%20multi-threaded.%20For%20each%20repository%2C%20we%20need%20to%20download%20it%20and%20parse%20files%20in%20it.%20And%20for%20each%20file%20in%20that%20repository%2C%20we%20need%20to%20parse%20and%20extract%20the%20information.%20Each%20of%20those%20operations%20doesn%E2%80%99t%20affect%20the%20others.%20Downloading%20a%20repository%20doesn%E2%80%99t%20affect%20extracting%20information%20from%20other%20repositories.%20Parsing%20a%20file%20doesn%E2%80%99t%20affect%20the%20other%20files.%20Those%20are%20good%20candidates%20for%20parallelism.%20We%20don%E2%80%99t%20manage%20threading%20directly%20ourselves.%20We%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fsystem.threading.tasks.parallel.foreach%3Fview%3Dnet-5.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EParallel.ForEach%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FDasync%2FAsyncEnumerable%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EParallelForEachExtensions.ParallelForEachAsync%3C%2FA%3E.%20Each%20allows%20us%20to%20configure%20maximum%20degree%20of%20parallelism.%20With%20that%20we%20can%20set%20the%20maximum%20degree%20of%20parallelism%20to%201%20when%20we%20debug%20the%20code.%20In%20the%20pipeline%2C%20we%20just%20use%20the%20default%20setting%20for%20the%20maximum%20degree%20of%20parallelism.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20we%20converted%20it%20to%20multi-threaded%2C%20it%20takes%20about%2013%20minutes%20in%20a%20typical%20run.%20While%20it%20took%2016%20minutes%20single%20threaded.%20There%20is%20about%2018%25%20improvement%20in%20the%20runtime.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1783010192%22%20id%3D%22toc-hId-1783163233%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--24444271%22%20id%3D%22toc-hId--24291230%22%3EDevelopment%20on%20Local%20Machines%3C%2FH2%3E%0A%3CP%3EWe%20used%20our%20Inventory%20system%20to%20store%20the%20data%20for%20re-use%20between%20smaller%20modules%20as%20well%20as%20between%20the%20runs%20on%20different%20local%20machines.%20All%20data%20is%20stored%20and%20shared%20in%20the%20Inventory%20system.%20This%20allows%20us%20to%20easily%20share%20data%20between%20machines.%20For%20example%2C%20when%20I%20am%20debugging%20an%20issue%20in%20an%20activity%2C%20I%20can%20ask%20my%20co-worker%20to%20help%20investigate%2C%20without%20the%20need%20to%20directly%20give%20them%20the%20input%20data.%20I%20just%20need%20to%20give%20them%20a%20reference%20to%20the%20version%20of%20the%20data%20used.%20My%20co-worker%20can%20then%20use%20this%20reference%20to%20reproduce%20the%20issue%20on%20their%20local%20machine%2C%20without%20having%20to%20run%20the%20activities%20that%20generated%20the%20input%20data%20to%20begin%20with.%20No%20process%20needs%20to%20be%20duplicated%3B%20we%20just%20need%20to%20focus%20on%20the%20activity%20being%20debugged.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe've%20come%20a%20long%20way%20from%20the%20first%20version%20we%20implemented.%20We%20have%20since%20then%20improved%20our%20pipeline%E2%80%99s%20performance%20and%20our%20engineering%20productivity.%20%26nbsp%3BWith%20those%20changes%2C%20we%20were%20able%20to%20reduce%20the%20time%20to%20run%20the%20whole%20pipeline%20from%208%20to%201.5%20hours.%20Our%20engineering%20productivity%20also%20improved%20by%20not%20having%20to%20run%20the%20whole%20pipeline%20just%20to%20verify%20our%20changes.%20But%20we%E2%80%99re%20not%20stopping%20here.%20There%20is%20still%20room%20to%20improve%20regarding%20performance%20and%20productivity.%20As%20we%20continue%20our%20journey%20in%20building%20AI%20model%20pipelines%20and%20services%2C%20we%20will%20share%20our%20learning%20with%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2712409%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20more%20about%20how%20we%20improved%20engineers'%20productivity%20by%20modularizing%20the%20training%20pipeline%20and%20improving%20run%20time%20performance.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2712409%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzureCLI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Sep 03 2021 09:29 AM
Updated by: