%3CLINGO-SUB%20id%3D%22lingo-sub-1426338%22%20slang%3D%22en-US%22%3ERe%3A%20Why%20use%20Azure%20Functions%20for%20ML%20inference%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1426338%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20is%20interesting.%26nbsp%3B%20We%20just%20moved%20some%20scheduled%20IoT%20processing%20_off_%20Azure%20functions%20for%20a%20few%20main%20reasons.%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3EThe%20lack%20of%20any%20persistent%20storage%20(the%20functionality%20needed%20to%20regularly%20scrape%20through%20a%20couple%20of%20GB%20of%20data)%26nbsp%3B%3C%2FLI%3E%3CLI%3EThe%20run-time%20limit%20of%2010%20minutes%20kept%20catching%20us%20out.%26nbsp%3B%26nbsp%3B%3C%2FLI%3E%3CLI%3EThe%20management%2Fmonitoring%20experience%20is%20pretty%20poor.%3C%2FLI%3E%3C%2FOL%3E%3CP%3ETo%20be%20fair%20our%20use%20case%20was%20more%20like%20a%20cron%20job%20on%20a%20%22VM-lite%22%26nbsp%3B%20-%20i.e.%20we%20were%20looking%20for%20a%20cheap%20way%20to%20run%20a%20scheduled%20job%20every%20few%20hours%20with%20a%20moderate%20amount%20of%20persistent%20storage%20that%20wouldn't%20incur%20the%20full%20cost%20of%20a%20VM%20but%20that%20also%20seems%20to%20apply%20here.%26nbsp%3B%20It%20sounds%20like%20the%20persistency%20issue%20can%20now%20be%20resolved%20using%20Azure%20files%20but%20I'm%20curious%20about%20the%20run-time%20limitation%20-%20surely%20this%20is%20a%20factor%20in%20ML%20applications%20as%20well%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1427121%22%20slang%3D%22en-US%22%3ERe%3A%20Why%20use%20Azure%20Functions%20for%20ML%20inference%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1427121%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20your%20comment%20NeliMacMullen.%20Yes%20for%20VM-lite%20scenarios%20-%20Premium%20Functions%20is%20a%20great%20option%20where%20the%20run%20time%20limit%20is%20increased%20to%201%20hour%20-%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-premium-plan%23longer-run-duration%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-premium-plan%23longer-run-duration%3C%2FA%3E%26nbsp%3B-%20The%20thing%20that%20you%20get%20here%20in%20addition%20to%20a%20standard%20VM%20is%20of-course%20all%20the%20triggering%20based%20on%20events%20and%20event%20based%20scale%20up%20and%20scale%20down%20(scale%20down%20to%201%20in%20this%20case)%20to%20handle%20any%20burst%20cases%20and%20then%20go%20back%20to%201%20instance%20when%20you%20are%20done.%20Further%20you%20get%20the%20local%20debug%20experience%20etc.%20with%20VSCode.%20And%20later%20if%20you%20ever%20want%20to%20deploy%20the%20same%20Function%20app%20to%20the%20Consumption%20app%20(10%20min.%20limit%2C%20cheaper)%20and%20even%20to%20Kubernetes%20it%20is%20very%20easy%20to%20do%20so.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1416728%22%20slang%3D%22en-US%22%3EWhy%20use%20Azure%20Functions%20for%20ML%20inference%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1416728%22%20slang%3D%22en-US%22%3E%3CBLOCKQUOTE%3E%0A%3CP%3EThis%20article%20highlights%20the%20current%20limitations%20in%20offerings%20by%20FaaS%20providers%20for%20ML%20inference%20applications%20and%20how%20capabilities%20in%20Azure%20Functions%20overcome%20these%20making%20it%20an%20ideal%20platform%20for%20such%20applications.%20It%20also%20links%20to%20an%20end%20to%20end%20%3CA%20href%3D%22%23sample%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esample%3C%2FA%3E%20illustrating%20these%20features.%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CH2%20id%3D%22ml-inference-in-faas-services%22%20id%3D%22toc-hId--1329469720%22%20id%3D%22toc-hId--1329469720%22%3EML%20Inference%20in%20FaaS%20Services%3C%2FH2%3E%0A%3CP%3EThe%20core%20promise%20of%20Serverless%2FFaaS%20(Functions%20as%20a%20Service)%20computing%20is%20to%20make%20it%20easier%20for%20developers%20to%20build%2C%20deploy%20and%20scale%20up%20their%20applications.%20Among%20the%20different%20kinds%20of%20applications%20-%20ML%20applications%20have%20seen%20an%20explosion%20in%20their%20usage%20and%20are%20now%20rapidly%20being%20deployed%20and%20bringing%20unprecedented%20novel%20capabilities%20in%20various%20domains.%3C%2FP%3E%0A%3CP%3EA%20typical%20ML%20workflow%20consists%20of%20using%20sample%20data%20to%20train%20a%20model%20and%20then%20use%20that%20model%20in%20an%20application%20to%20make%20predictions%20based%20on%20input.%20These%20stages%20are%20typically%20called%20%3CEM%3Etraining%3C%2FEM%3E%20and%20%3CEM%3Einference%3C%2FEM%3E%20respectively.%20On%20the%20surface%2C%20ML%20%3CEM%3Einference%3C%2FEM%3E%20should%20be%20a%20straightforward%20FaaS%20use%20case%20as%20essentially%20there%20is%20a%20single%20%22predict%22%20function%20that%20is%20called%20to%20%22infer%22%20the%20result%20for%20a%20particular%20input.%20However%2C%20due%20to%20various%20limits%20that%20typical%20FaaS%20platforms%20impose%20it%20hasn't%20been%20as%20optimum%20a%20platform%20that%20it%20can%20be.%20These%20are%20some%20of%20the%20limitations%3A%3C%2FP%3E%0A%3CH3%20id%3D%221-ml-libraries-can-be-big-%22%20id%3D%22toc-hId--638908246%22%20id%3D%22toc-hId--638908246%22%3E1.%20%3CSTRONG%3EML%20%3CEM%3Elibraries%3C%2FEM%3E%20can%20be%20big%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EML(especially%20Deep%20learning)%20libraries%20can%20be%20big%20in%20size.%20For%20example%20the%20%3CA%20href%3D%22https%3A%2F%2Fpytorch.org%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPyTorch%3C%2FA%3E%20(even%20the%20non-CUDA%20version)%20library%20is%20around%20~300MB.%20However%2C%20most%20FaaS%20providers%20only%20allow%20a%20maximum%20of%20~250MB-~500MB%20of%20deployed%20package%20size%20%3CEM%3Eincluding%3C%2FEM%3E%20any%20modules%20needed%20in%20the%20application.%20Customers%20have%20to%20resort%20to%20getting%20around%20to%20these%20limitations%20by%20compressing%20shared%20libraries%2C%20removing%20test%20folders%20etc.%3C%2FP%3E%0A%3CH3%20id%3D%222-python-ml-libraries-use-native-dependencies-%22%20id%3D%22toc-hId-1848604587%22%20id%3D%22toc-hId-1848604587%22%3E2.%20%3CSTRONG%3EPython%20ML%20%3CEM%3Elibraries%3C%2FEM%3E%20use%20native%20dependencies%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EMany%20Python%20ML%20libraries%20call%20into%20other%20C%2FC%2B%2B%20libraries%2C%20those%20need%20to%20be%20recompiled%20based%20on%20the%20OS%20causing%20a%20mismatch%20between%20the%20development%20and%20production%20deployments.%20For%20instance%2C%20developers%20using%20Windows%20have%20to%20resort%20to%20using%20Docker%20before%20deploying%20their%20FaaS%20application.%3C%2FP%3E%0A%3CH3%20id%3D%223-ml-models-can-be-big-%22%20id%3D%22toc-hId-41150124%22%20id%3D%22toc-hId-41150124%22%3E3.%20%3CSTRONG%3EML%20%3CEM%3Emodels%3C%2FEM%3E%20can%20be%20big%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3ESome%20of%20the%20latest%20ML%20models%20can%20be%20very%20big%20in%20size%20-%20for%20example%20the%20%3CA%20href%3D%22https%3A%2F%2Farxiv.org%2Fabs%2F1404.5997%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAlexNet%3C%2FA%3E%20pre-trained%20%3CA%20href%3D%22https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorchvision%2Fmodels.html%23id1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPyTorch%20model%3C%2FA%3E%20is%20230MB.%20Some%20models%20like%20%3CA%20href%3D%22https%3A%2F%2Fopenai.com%2Fblog%2Fgpt-2-1-5b-release%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGPT-2%3C%2FA%3E%20can%20be%20several%20GB%20in%20size.%20FaaS%20offerings%20have%20a%20limited%20deployment%20size%20package%20as%20mentioned%20above%20-%20further%2C%20they%20don't%20offer%20a%20way%20to%20separate%20out%20the%20model%20from%20the%20code%20by%20mounting%20a%20file%20system%20for%20instance.%3C%2FP%3E%0A%3CP%3EFurther%2C%20some%20large%20models%20need%20to%20be%20completely%20loaded%20into%20memory%20before%20they%20can%20be%20used%20and%20amount%20of%20memory%20offered%20in%20current%20FaaS%20offerings%20might%20not%20be%20enough.%3C%2FP%3E%0A%3CH3%20id%3D%224-concurrency-models-for-i-o-bound-invocations-are-sub-optimal-%22%20id%3D%22toc-hId--1766304339%22%20id%3D%22toc-hId--1766304339%22%3E4.%20%3CSTRONG%3EConcurrency%20models%20for%20I%2FO%20bound%20invocations%20are%20sub-optimal%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EMany%20ML%20inference%20API's%20are%20typically%20I%2FO%20bound%2C%20however%2C%20in%20current%20FaaS%20execution%20frameworks%20a%20single%20instance%20cannot%20handle%20concurrent%20requests.%20The%20can%20lead%20to%20a%20lot%20of%20wasted%20idle%20resources%20on%20individual%20instances.%3C%2FP%3E%0A%3CH3%20id%3D%225-cold-start-%22%20id%3D%22toc-hId-721208494%22%20id%3D%22toc-hId-721208494%22%3E5.%20%3CSTRONG%3ECold%20start%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EFaaS%20workloads%20scale%20down%20to%20zero%20instances%20when%20not%20being%20used%2C%20therefore%20starting%20a%20new%20instance%20always%20incurs%20lag%20-%20which%20is%20called%20cold%20start.%20For%20many%20applications%20this%20lag%20is%20not%20acceptable.%3C%2FP%3E%0A%3CH3%20id%3D%226-gpu-support-is-not-available-%22%20id%3D%22toc-hId--1086245969%22%20id%3D%22toc-hId--1086245969%22%3E6.%20%3CSTRONG%3EGPU%20support%20is%20not%20available%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EMany%20inference%20applications%20have%20a%20very%20stringent%20latency%20requirements%20(think%20for%20instance%20applications%20related%20to%20providing%20auto-suggestions%20as%20you%20type).%20To%20meet%20these%20latency%20requirements%20often%20(especially%20for%20bigger%20models)%20GPU%20processing%20can%20lead%20to%20several%20times%20of%20improvement.%20However%20FaaS%20providers%20currently%20do%20not%20support%20GPU's.%3C%2FP%3E%0A%3CH3%20id%3D%227-no-native-support-for-long-running-ml-workloads-and-or-orchestration-patterns-%22%20id%3D%22toc-hId-1401266864%22%20id%3D%22toc-hId-1401266864%22%3E7.%20%3CSTRONG%3ENo%20native%20support%20for%20long%20running%20ML%20workloads%20and%2For%20orchestration%20patterns%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3ESome%20ML%20workloads%20might%20be%20inherently%20long%20running%20and%2For%20have%20complex%20orchestration%20needs.%20Current%20FaaS%20providers%20do%20not%20offer%20native%20frameworks%20for%20these%20scenarios%20and%20customers%20need%20to%20resort%20to%20external%20services%20and%20built%20the%20complex%20coordination%20logic%20themselves.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22azure-functions-python%22%20id%3D%22toc-hId-1390763760%22%20id%3D%22toc-hId-1390763760%22%3EAzure%20Functions%20Python%3C%2FH2%3E%0A%3CP%3EIn%20Azure%20Functions%20Python%20capabilities%20and%20features%20have%20been%20added%20to%20overcome%20some%20of%20the%20above%20limitations%20and%20make%20it%20a%20first%20class%20option%20for%20ML%20inference%20with%20all%20the%20traditional%20FaaS%20benefits%20of%20scaling%20on%20demand%2C%20fast%20iteration%20and%20pay-for-use.%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2FAzure-Samples%2Fazure-functions-pytorch-image-identify%2Fmaster%2Fmedia%2Fteaser.png%22%20border%3D%220%22%20alt%3D%22azure-functions-ml%22%20%2F%3E%3C%2FP%3E%0A%3CH3%20id%3D%221-higher-deployment-package-sizes-%22%20id%3D%22toc-hId-2081325234%22%20id%3D%22toc-hId-2081325234%22%3E1.%20%3CSTRONG%3EHigher%20deployment%20package%20sizes%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EAzure%20Functions%20support%20higher%20deployment%20packages%20as%20much%20as%20several%20GB%20in%20size.%20This%20means%20that%20even%20larger%20deep%20learning%20frameworks%20like%20TensorFlow%20and%20PyTorch%20can%20be%20supported%20out%20of%20the%20box%20without%20resorting%20to%20having%20to%20reduce%20their%20size.%3C%2FP%3E%0A%3CH3%20id%3D%222-support-for-remote-build-%22%20id%3D%22toc-hId--421292708%22%20id%3D%22toc-hId--421292708%22%3E2.%20%3CSTRONG%3ESupport%20for%20Remote%20Build%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EAs%20mentioned%20above%2C%20many%20Python%20libraries%20have%20native%20dependencies.%20This%20means%20if%20you%20are%20developing%20your%20application%20on%20Windows%20and%20then%20deploy%20it%20in%20production%20which%20typically%20is%20on%20Linux%20-%20it%20might%20not%20work%20as%20they%20have%20to%20be%20recompiled%20to%20work%20on%20another%20operating%20system.%3C%2FP%3E%0A%3CP%3ETo%20help%20with%20this%20problem%20in%20Azure%20Functions%20we%20built%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-reference-python%23remote-build%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERemote%20Build%3C%2FA%3E%20functionality%2C%20where%20we%20automatically%20compile%20and%20pull%20in%20the%20right%20libraries%20on%20the%20server%20side.%20Hence%2C%20they%20don't%20have%20to%20be%20included%20in%20your%20deployment%20package%20locally%20and%20only%20need%20to%20be%20referenced%20in%20your%20requirements.txt%20file.%20This%20is%20the%20default%20experience%20when%20using%20VSCode%20or%20the%20func%20core%20tools%20to%20deploy%20your%20Python%20Azure%20Functions%20application.%20This%20is%20a%20snippet%20from%20the%20deployment%20logs%20showing%20the%20libraries%20being%20installed%20on%20the%20server%20side.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%3E12%3A02%3A54%20AM%20pytorch-image-consumption%3A%20Starting%20deployment...%0A.%0A12%3A03%3A01%20AM%20pytorch-image-consumption%3A%20Running%20pip%20install...%0A...%0A12%3A03%3A14%20AM%20pytorch-image-consumption%3A%20%5B07%3A03%3A14%3CSPAN%20class%3D%22hljs-string%22%3E%2B0000%3C%2FSPAN%3E%5D%20Collecting%20torch%3D%3D1.4.0%2Bcpu%0A12%3A03%3A14%20AM%20pytorch-image-consumption%3A%20%5B07%3A03%3A14%3CSPAN%20class%3D%22hljs-string%22%3E%2B0000%3C%2FSPAN%3E%5D%20%20%20Downloading%20https%3A%2F%2Fdownload.pytorch.org%2Fwhl%2Fcpu%2Ftorch%3CSPAN%20class%3D%22hljs-string%22%3E-1%3C%2FSPAN%3E.4.0%252Bcpu-cp37-cp37m-linux_x86_64.whl%20(127.2MB)%0A12%3A03%3A45%20AM%20pytorch-image-consumption%3A%20%5B07%3A03%3A45%3CSPAN%20class%3D%22hljs-string%22%3E%2B0000%3C%2FSPAN%3E%5D%20Collecting%20torchvision%3D%3D0.5.0%0A12%3A03%3A45%20AM%20pytorch-image-consumption%3A%20%5B07%3A03%3A45%3CSPAN%20class%3D%22hljs-string%22%3E%2B0000%3C%2FSPAN%3E%5D%20%20%20Downloading%20https%3A%2F%2Ffiles.pythonhosted.org%2Fpackages%2F1c%2F32%2Fcb0e4c43cd717da50258887b088471568990b5a749784c465a8a1962e021%2Ftorchvision%3CSPAN%20class%3D%22hljs-string%22%3E-0%3C%2FSPAN%3E.5.0-cp37-cp37m-manylinux1_x86_64.whl%20(4.0MB)%0A....%0A12%3A04%3A08%20AM%20pytorch-image-consumption%3A%20%5B07%3A04%3A08%3CSPAN%20class%3D%22hljs-string%22%3E%2B0000%3C%2FSPAN%3E%5D%20Successfully%20installed%20azure-functions%3CSPAN%20class%3D%22hljs-string%22%3E-1%3C%2FSPAN%3E.2.1%20certifi%3CSPAN%20class%3D%22hljs-string%22%3E-2020%3C%2FSPAN%3E.4.5.1%20chardet%3CSPAN%20class%3D%22hljs-string%22%3E-3%3C%2FSPAN%3E.0.4%20idna%3CSPAN%20class%3D%22hljs-string%22%3E-2%3C%2FSPAN%3E.9%20numpy%3CSPAN%20class%3D%22hljs-string%22%3E-1%3C%2FSPAN%3E.15.4%20pillow%3CSPAN%20class%3D%22hljs-string%22%3E-7%3C%2FSPAN%3E.1.2%20requests%3CSPAN%20class%3D%22hljs-string%22%3E-2%3C%2FSPAN%3E.23.0%20six%3CSPAN%20class%3D%22hljs-string%22%3E-1%3C%2FSPAN%3E.14.0%20torch%3CSPAN%20class%3D%22hljs-string%22%3E-1%3C%2FSPAN%3E.4.0%2Bcpu%20torchvision%3CSPAN%20class%3D%22hljs-string%22%3E-0%3C%2FSPAN%3E.5.0%20urllib3%3CSPAN%20class%3D%22hljs-string%22%3E-1%3C%2FSPAN%3E.25.9%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CH3%20id%3D%223-support-for-mounting-an-external-file-system-through-azure-files-%22%20id%3D%22toc-hId-2066220125%22%20id%3D%22toc-hId-2066220125%22%3E3.%20%3CSTRONG%3ESupport%20for%20mounting%20an%20external%20file%20system%20through%20Azure%20Files%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3ETo%20allow%20for%20arbitrarily%20large%20ML%20models%20and%20to%20separate%20the%20workflow%20of%20building%20the%20application%20and%20training%20your%20ML%20model%20the%20capability%20to%20automatically%20mount%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Fscripts%2Ffunctions-cli-mount-files-storage-linux%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Econfigured%20Azure%20file%20share%3C%2FA%3E%20has%20been%20recently%20introduced.%3C%2FP%3E%0A%3CP%3EThis%20is%20as%20simple%20as%20using%20an%20Azure%20CLI%20command%20where%20the%20%3CEM%3E%24shareName%3C%2FEM%3E%20Azure%20File%20share%20will%20automatically%20be%20mounted%20whenever%20the%20%3CEM%3E%24functionAppName%3C%2FEM%3E%20Function%20app%20starts%20up.%20The%20path%20available%20to%20the%20Function%20app%20will%20be%20with%20the%20name%20of%20%3CEM%3E%24mountPath%3C%2FEM%3E.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22lang-bash%22%3Eaz%20webapp%20config%20storage-account%20add%20%5C%0A%20%20-%3CSPAN%20class%3D%22ruby%22%3E-resource-group%20myResourceGroup%20%5C%0A%3C%2FSPAN%3E%20%20-%3CSPAN%20class%3D%22ruby%22%3E-name%20%24functionAppName%20%5C%0A%3C%2FSPAN%3E%20%20-%3CSPAN%20class%3D%22ruby%22%3E-custom-id%20%24shareId%20%5C%0A%3C%2FSPAN%3E%20%20-%3CSPAN%20class%3D%22ruby%22%3E-storage-type%20AzureFiles%20%5C%0A%3C%2FSPAN%3E%20%20-%3CSPAN%20class%3D%22ruby%22%3E-share-name%20%24shareName%20%5C%0A%3C%2FSPAN%3E%20%20-%3CSPAN%20class%3D%22ruby%22%3E-account-name%20%24AZURE_STORAGE_ACCOUNT%20%5C%0A%3C%2FSPAN%3E%20%20-%3CSPAN%20class%3D%22ruby%22%3E-mount-path%20%24mountPath%20%5C%0A%3C%2FSPAN%3E%20%20-%3CSPAN%20class%3D%22ruby%22%3E-access-key%20%24AZURE_STORAGE_KEY%3C%2FSPAN%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EThis%20is%20an%20Azure%20Files%20storage%20view%20with%20two%20different%20models.%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2FAzure-Samples%2Fazure-functions-pytorch-image-identify%2Fmaster%2Fmedia%2Fstorage-account-file-share.png%22%20border%3D%220%22%20alt%3D%22azure-files%22%20%2F%3E%3C%2FP%3E%0A%3CP%3EThis%20functionality%20is%20available%20both%20in%20the%20Consumption%20and%20Premium%20plans.%20It%20is%20also%20worth%20noting%20that%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Ffiles%2Fstorage-how-to-create-premium-fileshare%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Files%20have%20a%20Premium%20tier%3C%2FA%3E%20which%20can%20be%20used%20as%20well%20-%20it%20offers%20a%20higher%20level%20of%20performance%20i.e.%20high%20throughput%20and%20low%20latency%20for%20IO-intensive%20workloads(many%20ML%20applications)%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3EThe%20above%20two%20features%20Remote%20Build%20and%20support%20for%20Azure%20Files%20allow%20the%20deployment%20package%20to%20be%20much%20smaller.%20For%20example%2C%20in%20the%20PyTorch%20%3CA%20href%3D%22%23sample%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esample%3C%2FA%3E%20referenced%20below%20the%20total%20package%20size%20would%20have%20been%20close%20to%20520MB%20in%20size%20when%20using%20the%20resnet100%20model%20(~350MB%20for%20PyTorch%20and%20~170MB%20for%20the%20model)%20while%20without%20it%20it%20is%20barely%2050KB%20in%20size.%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CH3%20id%3D%224-azure-functions-concurrency-model-is-optimal-for-i-o-bound-invocations-%22%20id%3D%22toc-hId-258765662%22%20id%3D%22toc-hId-258765662%22%3E4.%20%3CSTRONG%3EAzure%20Functions%20concurrency%20model%20is%20optimal%20for%20I%2FO%20bound%20invocations%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EIn%20Azure%20Functions%20-%20the%20same%20instance%20is%20re-used%20for%20concurrent%20calls.%20This%20can%20lead%20to%20optimum%20use%20of%20resources%20especially%20for%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-reference-python%23scaling-and-concurrency%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Econcurrent%20I%2FO%20bound%20invocations%3C%2FA%3E%20where%20the%20underlying%20api%20has%20async%20variants.%3C%2FP%3E%0A%3CH3%20id%3D%225-azure-functions-premium-sku-s-offer-higher-memory-limits-and-no-cold-start-%22%20id%3D%22toc-hId--1548688801%22%20id%3D%22toc-hId--1548688801%22%3E5.%20%3CSTRONG%3EAzure%20Functions%20Premium%20SKU's%20offer%20higher%20memory%20limits%20and%20no%20cold%20start%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-premium-plan%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EThe%20Azure%20Functions%20Premium%20SKU%3C%2FA%3E%20offers%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-premium-plan%23available-instance-skus%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehigher%20memory%20limits%20-%20up%20to%2014GB%3C%2FA%3E%20for%20cases%20where%20you%20would%20want%20to%20load%20the%20entire%20model%20in%20memory.%3C%2FP%3E%0A%3CTABLE%3E%0A%3CTHEAD%3E%0A%3CTR%3E%0A%3CTH%3ESKU%3C%2FTH%3E%0A%3CTH%3ECores%3C%2FTH%3E%0A%3CTH%3EMemory%3C%2FTH%3E%0A%3CTH%3EStorage%3C%2FTH%3E%0A%3C%2FTR%3E%0A%3C%2FTHEAD%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%3EEP1%3C%2FTD%3E%0A%3CTD%3E1%3C%2FTD%3E%0A%3CTD%3E3.5GB%3C%2FTD%3E%0A%3CTD%3E250GB%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3EEP2%3C%2FTD%3E%0A%3CTD%3E2%3C%2FTD%3E%0A%3CTD%3E7GB%3C%2FTD%3E%0A%3CTD%3E250GB%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3EEP3%3C%2FTD%3E%0A%3CTD%3E4%3C%2FTD%3E%0A%3CTD%3E14GB%3C%2FTD%3E%0A%3CTD%3E250GB%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%20class%3D%22code-line%20code-line%20code-line%22%20data-line%3D%2295%22%3EIt%20also%20avoids%26nbsp%3B%3CA%20title%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-premium-plan%23pre-warmed-instances%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-premium-plan%23pre-warmed-instances%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%20data-href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-premium-plan%23pre-warmed-instances%22%3Ecold%20start%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Efor%20those%20applications%20where%20there%20cannot%20be%20any%20latency%20at%20all.%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22code-line%20code-line%20code-line%22%20data-line%3D%2297%22%3EFurther%2C%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20title%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-create-function-linux-custom-image%3Ftabs%3Dbash%252Cportal%26amp%3Bpivots%3Dprogramming-language-python%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-create-function-linux-custom-image%3Ftabs%3Dbash%252Cportal%26amp%3Bpivots%3Dprogramming-language-python%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%20data-href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-create-function-linux-custom-image%3Ftabs%3Dbash%252Cportal%26amp%3Bpivots%3Dprogramming-language-python%22%3Ecustom%20container%20support%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eenables%20integration%20with%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20title%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmachine-learning%2Fhow-to-deploy-functions%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmachine-learning%2Fhow-to-deploy-functions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%20data-href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmachine-learning%2Fhow-to-deploy-functions%22%3EAzure%20Machine%20Learning%20service%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Esuch%20that%20you%20can%20package%20a%20model%20from%20the%20Azure%20ML%20service%20into%20an%20Azure%20Function%20Premium%20app%20and%20allows%20the%20use%20of%20a%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20title%3D%22https%3A%2F%2Fgithub.com%2FHazhzeng%2Ffunctions-conda%22%20href%3D%22https%3A%2F%2Fgithub.com%2FHazhzeng%2Ffunctions-conda%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%20data-href%3D%22https%3A%2F%2Fgithub.com%2FHazhzeng%2Ffunctions-conda%22%3EConda%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eenvironment.%3C%2FP%3E%0A%3CH3%20id%3D%226-deploy-azure-functions-to-a-kubernetes-cluster-with-gpu-support-%22%20id%3D%22toc-hId-938824032%22%20id%3D%22toc-hId-938824032%22%3E6.%20%3CSTRONG%3EDeploy%20Azure%20Functions%20to%20a%20Kubernetes%20cluster%20with%20GPU%20support%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EFinally%2C%20as%20in%20Azure%20Functions%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-functions-host%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eprogramming%20model%3C%2FA%3E%20is%20separate%20from%20the%20deployment%20target%2C%20an%20Azure%20Function%20app%20can%20be%20deployed%20to%20a%20Kubernetes%20cluster%20(it%20can%20be%20scaled%20up%20and%20down%20using%20%3CA%20href%3D%22http%3A%2F%2Fkeda.sh%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EKEDA%3C%2FA%3E).%20Many%20managed%20Kubernetes%20offering%20(including%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Faks%2Fgpu-cluster%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAKS%3C%2FA%3E)%20have%20GPU%20support.%3C%2FP%3E%0A%3CH3%20id%3D%227-orchestrating-inference-invocations-durable-functions-python-%22%20id%3D%22toc-hId--868630431%22%20id%3D%22toc-hId--868630431%22%3E7.%20%3CSTRONG%3EOrchestrating%20inference%20invocations%20-%20Durable%20Functions%20Python%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EWith%20the%20impending%20release%20of%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-functions-durable-python%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EDurable%20Functions%20Python%3C%2FA%3E%20long%20running%20ML%20workloads%20can%20now%20be%20supported.%20Durable%20Functions%20allows%20many%20different%20orchestration%20use%20cases%20including%20processing%20multiple%20inputs%20in%20a%20batch%2C%20parallelizing%20classification%20tasks%20etc.%20These%20are%20enabled%20by%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-functions-durable-python%2Ftree%2Fdev%2Fsamples%2Ffunction_chaining%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EChaining%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-functions-durable-python%2Ftree%2Fdev%2Fsamples%2Ffan_out_fan_in%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EFan-Out%20Fan-In%3C%2FA%3E%20and%20other%20Durable%20Function%20patterns.%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-functions-durable-python%2Ftree%2Fdev%2Fsamples%2Ffan_out_fan_in_tensorflow%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EThis%20sample%3C%2FA%3E%20illustrates%20the%20use%20of%20the%20Fan-Out%20Fan-In%20pattern%20doing%20parallel%20image%20classification%20using%20%3CA%20href%3D%22https%3A%2F%2Fwww.tensorflow.org%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ETensorFlow%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22sample%22%20id%3D%22toc-hId-1489799683%22%20id%3D%22toc-hId-1489799683%22%3ESample%3C%2FH2%3E%0A%3CP%3ETo%20put%20this%20all%20together%20and%20show%20a%20real%20end%20to%20end%20example%20-%20please%20find%20a%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2Fazure-functions-pytorch-image-identify%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Estep%20by%20step%20walk%20through%20example%20of%20an%20Azure%20Function%20app%3C%2FA%3E%26nbsp%3Bwhich%20shows%20how%20these%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fpytorch.org%2Fdocs%2Fstable%2Ftorchvision%2Fmodels.html%23classification%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Epre-trained%20PyTorch%20models%3C%2FA%3E%26nbsp%3Bcan%20be%20loaded%20from%20an%20Azure%20File%20share%20in%20an%20ML%20inference%20application%20which%20classifies%20images.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fraw.githubusercontent.com%2FAzure-Samples%2Fazure-functions-pytorch-image-identify%2Fmaster%2Fmedia%2Fpytorch-models.png%22%20border%3D%220%22%20alt%3D%22pytorch-models%22%20%2F%3E%3C%2FP%3E%0A%3CP%3EIt%20illustrates%20the%20use%20of%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-reference-python%23remote-build%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERemote%20Build%3C%2FA%3E%2C%20gives%20guidance%20on%20how%20you%20can%20deploy%20the%20same%20app%20to%20the%20Premium%20plan%20for%20no-cold%20start%20and%20higher%20memory%20limits%20and%20gives%20guidance%20on%20how%20the%20same%20app%20can%20be%20deployed%20to%20a%20AKS%20cluster%20with%20GPU.%20More%20end%20to%20end%20examples%20will%20be%20added%20soon%20for%20text%20generation%20and%20other%20ML%20tasks.%3C%2FP%3E%0A%3CP%3EHopefully%20this%20blog%20post%20encourages%20you%20to%20consider%20Azure%20Functions%20for%20your%20ML%20inference%20applications.%20Please%20ask%20any%20questions%20in%20the%20comments%2C%20or%20open%20any%20issues%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-functions-python-worker%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Functions%20Python%20Worker%20repo%3C%2FA%3E%20or%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2Fazure-functions-pytorch-image-identify%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Esample%20repo%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1416728%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22teaser.png%22%20style%3D%22width%3A%20690px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F194329i760C2FDD6CCCBF70%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22teaser.png%22%20alt%3D%22teaser.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1416728%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

This article highlights the current limitations in offerings by FaaS providers for ML inference applications and how capabilities in Azure Functions overcome these making it an ideal platform for such applications. It also links to an end to end sample illustrating these features.

ML Inference in FaaS Services

The core promise of Serverless/FaaS (Functions as a Service) computing is to make it easier for developers to build, deploy and scale up their applications. Among the different kinds of applications - ML applications have seen an explosion in their usage and are now rapidly being deployed and bringing unprecedented novel capabilities in various domains.

A typical ML workflow consists of using sample data to train a model and then use that model in an application to make predictions based on input. These stages are typically called training and inference respectively. On the surface, ML inference should be a straightforward FaaS use case as essentially there is a single "predict" function that is called to "infer" the result for a particular input. However, due to various limits that typical FaaS platforms impose it hasn't been as optimum a platform that it can be. These are some of the limitations:

1. ML libraries can be big

ML(especially Deep learning) libraries can be big in size. For example the PyTorch (even the non-CUDA version) library is around ~300MB. However, most FaaS providers only allow a maximum of ~250MB-~500MB of deployed package size including any modules needed in the application. Customers have to resort to getting around to these limitations by compressing shared libraries, removing test folders etc.

2. Python ML libraries use native dependencies

Many Python ML libraries call into other C/C++ libraries, those need to be recompiled based on the OS causing a mismatch between the development and production deployments. For instance, developers using Windows have to resort to using Docker before deploying their FaaS application.

3. ML models can be big

Some of the latest ML models can be very big in size - for example the AlexNet pre-trained PyTorch model is 230MB. Some models like GPT-2 can be several GB in size. FaaS offerings have a limited deployment size package as mentioned above - further, they don't offer a way to separate out the model from the code by mounting a file system for instance.

Further, some large models need to be completely loaded into memory before they can be used and amount of memory offered in current FaaS offerings might not be enough.

4. Concurrency models for I/O bound invocations are sub-optimal

Many ML inference API's are typically I/O bound, however, in current FaaS execution frameworks a single instance cannot handle concurrent requests. The can lead to a lot of wasted idle resources on individual instances.

5. Cold start

FaaS workloads scale down to zero instances when not being used, therefore starting a new instance always incurs lag - which is called cold start. For many applications this lag is not acceptable.

6. GPU support is not available

Many inference applications have a very stringent latency requirements (think for instance applications related to providing auto-suggestions as you type). To meet these latency requirements often (especially for bigger models) GPU processing can lead to several times of improvement. However FaaS providers currently do not support GPU's.

7. No native support for long running ML workloads and/or orchestration patterns

Some ML workloads might be inherently long running and/or have complex orchestration needs. Current FaaS providers do not offer native frameworks for these scenarios and customers need to resort to external services and built the complex coordination logic themselves.

 

Azure Functions Python

In Azure Functions Python capabilities and features have been added to overcome some of the above limitations and make it a first class option for ML inference with all the traditional FaaS benefits of scaling on demand, fast iteration and pay-for-use.

azure-functions-ml

1. Higher deployment package sizes

Azure Functions support higher deployment packages as much as several GB in size. This means that even larger deep learning frameworks like TensorFlow and PyTorch can be supported out of the box without resorting to having to reduce their size.

2. Support for Remote Build

As mentioned above, many Python libraries have native dependencies. This means if you are developing your application on Windows and then deploy it in production which typically is on Linux - it might not work as they have to be recompiled to work on another operating system.

To help with this problem in Azure Functions we built the Remote Build functionality, where we automatically compile and pull in the right libraries on the server side. Hence, they don't have to be included in your deployment package locally and only need to be referenced in your requirements.txt file. This is the default experience when using VSCode or the func core tools to deploy your Python Azure Functions application. This is a snippet from the deployment logs showing the libraries being installed on the server side.

12:02:54 AM pytorch-image-consumption: Starting deployment...
.
12:03:01 AM pytorch-image-consumption: Running pip install...
...
12:03:14 AM pytorch-image-consumption: [07:03:14+0000] Collecting torch==1.4.0+cpu
12:03:14 AM pytorch-image-consumption: [07:03:14+0000]   Downloading https://download.pytorch.org/whl/cpu/torch-1.4.0%2Bcpu-cp37-cp37m-linux_x86_64.whl (127.2MB)
12:03:45 AM pytorch-image-consumption: [07:03:45+0000] Collecting torchvision==0.5.0
12:03:45 AM pytorch-image-consumption: [07:03:45+0000]   Downloading https://files.pythonhosted.org/packages/1c/32/cb0e4c43cd717da50258887b088471568990b5a749784c465a8a1962e021/torchvision-0.5.0-cp37-cp37m-manylinux1_x86_64.whl (4.0MB)
....
12:04:08 AM pytorch-image-consumption: [07:04:08+0000] Successfully installed azure-functions-1.2.1 certifi-2020.4.5.1 chardet-3.0.4 idna-2.9 numpy-1.15.4 pillow-7.1.2 requests-2.23.0 six-1.14.0 torch-1.4.0+cpu torchvision-0.5.0 urllib3-1.25.9

3. Support for mounting an external file system through Azure Files

To allow for arbitrarily large ML models and to separate the workflow of building the application and training your ML model the capability to automatically mount a configured Azure file share has been recently introduced.

This is as simple as using an Azure CLI command where the $shareName Azure File share will automatically be mounted whenever the $functionAppName Function app starts up. The path available to the Function app will be with the name of $mountPath.

az webapp config storage-account add \
  --resource-group myResourceGroup \
  --name $functionAppName \
  --custom-id $shareId \
  --storage-type AzureFiles \
  --share-name $shareName \
  --account-name $AZURE_STORAGE_ACCOUNT \
  --mount-path $mountPath \
  --access-key $AZURE_STORAGE_KEY

This is an Azure Files storage view with two different models.

azure-files

This functionality is available both in the Consumption and Premium plans. It is also worth noting that Azure Files have a Premium tier which can be used as well - it offers a higher level of performance i.e. high throughput and low latency for IO-intensive workloads(many ML applications)

The above two features Remote Build and support for Azure Files allow the deployment package to be much smaller. For example, in the PyTorch sample referenced below the total package size would have been close to 520MB in size when using the resnet100 model (~350MB for PyTorch and ~170MB for the model) while without it it is barely 50KB in size.

4. Azure Functions concurrency model is optimal for I/O bound invocations

In Azure Functions - the same instance is re-used for concurrent calls. This can lead to optimum use of resources especially for concurrent I/O bound invocations where the underlying api has async variants.

5. Azure Functions Premium SKU's offer higher memory limits and no cold start

The Azure Functions Premium SKU offers higher memory limits - up to 14GB for cases where you would want to load the entire model in memory.

SKU Cores Memory Storage
EP1 1 3.5GB 250GB
EP2 2 7GB 250GB
EP3 4 14GB 250GB

It also avoids cold start for those applications where there cannot be any latency at all. 

Further, the custom container support enables integration with the Azure Machine Learning service such that you can package a model from the Azure ML service into an Azure Function Premium app and allows the use of a Conda environment.

6. Deploy Azure Functions to a Kubernetes cluster with GPU support

Finally, as in Azure Functions the programming model is separate from the deployment target, an Azure Function app can be deployed to a Kubernetes cluster (it can be scaled up and down using KEDA). Many managed Kubernetes offering (including AKS) have GPU support.

7. Orchestrating inference invocations - Durable Functions Python

With the impending release of Durable Functions Python long running ML workloads can now be supported. Durable Functions allows many different orchestration use cases including processing multiple inputs in a batch, parallelizing classification tasks etc. These are enabled by the Chaining, Fan-Out Fan-In and other Durable Function patterns. This sample illustrates the use of the Fan-Out Fan-In pattern doing parallel image classification using TensorFlow.

 

Sample

To put this all together and show a real end to end example - please find a step by step walk through example of an Azure Function app which shows how these pre-trained PyTorch models can be loaded from an Azure File share in an ML inference application which classifies images.

 

pytorch-models

It illustrates the use of Remote Build, gives guidance on how you can deploy the same app to the Premium plan for no-cold start and higher memory limits and gives guidance on how the same app can be deployed to a AKS cluster with GPU. More end to end examples will be added soon for text generation and other ML tasks.

Hopefully this blog post encourages you to consider Azure Functions for your ML inference applications. Please ask any questions in the comments, or open any issues in the Azure Functions Python Worker repo or in the sample repo.

2 Comments
Occasional Visitor

This is interesting.  We just moved some scheduled IoT processing _off_ Azure functions for a few main reasons. 

  1. The lack of any persistent storage (the functionality needed to regularly scrape through a couple of GB of data) 
  2. The run-time limit of 10 minutes kept catching us out.  
  3. The management/monitoring experience is pretty poor.

To be fair our use case was more like a cron job on a "VM-lite"  - i.e. we were looking for a cheap way to run a scheduled job every few hours with a moderate amount of persistent storage that wouldn't incur the full cost of a VM but that also seems to apply here.  It sounds like the persistency issue can now be resolved using Azure files but I'm curious about the run-time limitation - surely this is a factor in ML applications as well?

Microsoft

Thanks for your comment NeliMacMullen. Yes for VM-lite scenarios - Premium Functions is a great option where the run time limit is increased to 1 hour - https://docs.microsoft.com/en-us/azure/azure-functions/functions-premium-plan#longer-run-duration - The thing that you get here in addition to a standard VM is of-course all the triggering based on events and event based scale up and scale down (scale down to 1 in this case) to handle any burst cases and then go back to 1 instance when you are done. Further you get the local debug experience etc. with VSCode. And later if you ever want to deploy the same Function app to the Consumption app (10 min. limit, cheaper) and even to Kubernetes it is very easy to do so.