Why do we write machine learning architecture with Go, but do not have Python?


"If you are interested in becoming a machine learning engineer, you must be familiar with Python-- However, if you are interested in infrastructure, machine learning, you should give serious consideration to Go. "

Author |  Caleb Kaiser

Translator | meniscus, Zebian | Guo Rui

Exhibition | CSDN (ID: CSDNnews)

The following is the translation:

Today, well-known machine learning Python is the most popular language in the project. Although R, C ++ and other languages, and Julia have their supporters and usage, but Python is still the most commonly used language, almost every mainstream machine learning framework uses the Python.

However, in our Cortex (for machine learning models to deploy open source platform API) code base, 87.5% of the code is Go.

Python proud of machine learning algorithm is just a part of the production machine learning system. If you want to run large-scale production of machine learning API, your infrastructure needs to achieve the following functions:

  • Automatic scaling, ensure flow fluctuations will not affect the API.

  • API management, process synchronization API deployment.

  • Scroll updated to ensure that the service will not be interrupted when users update the model.

We built Cortex is to automate all of the above infrastructure, as well as logging and other issues such as cost optimization.

For the following reasons, we believe that Go is the ideal choice for building software that meet these needs.

Concurrent crucial for infrastructure Machine Learning

Users can deploy many different models into different API, and all models are put to manage with a Cortex cluster. Cortex Operator needs through some API to manage these different deployment, such as:

  • Kubernetes API, Cortex API calls this deployment model on a cluster.

  • Various AWS API, including EC2 Auto Scaling, S3, CloudWatch, etc., Cortex call these API to manage deployed on AWS.

Users do not interact directly with the API. Cortex by calling the API program to manage the cluster, start to deploy and monitor API.

以高效、可靠的方式交叉调用这些API是一项难题。采用并发的方式处理这些API调用是最为高效的方式,但同时也带来了复杂性,因为我们不得不担心竞争状况等问题。

Go为解决这个问题提供了一个开箱即用的解决方案:Goroutines。

Goroutines是Go以并发的方式执行代码的函数。我们可以另写一篇文章深入探讨Goroutines背后的工作方式,但概括来说,Goroutines是由Go运行时自动管理的轻量级线程。你可以将多个Goroutine放在一个OS线程上,而且如果Goroutine阻塞了OS线程,则Go运行时会自动将其余的Goroutines移到新的OS线程上。

Goroutines还提供了一种名叫“通道”(channel)的功能,你可以利用这个功能在Goroutines之间传递消息,帮助我们调度请求并防止出现竞争状况。

当然,你也可以利用asyncio等最新的工具在Python中实现这些功能,但Go的设计考虑到了这些情况,使用Go可以减轻我们的工作负担。

使用Go构建跨平台的CLI更容易

Cortex CLI是一个跨平台工具,用户可以使用这个工具直接从命令行部署模型和管理API。

最初,我们使用Python编写了这个CLI,但事实证明,在多个平台上分发这个CLI太困难了。由于Go可以编译成一个二进制文件(不需要管理依赖),所以可以为我们提供了一个简单的解决方案,帮助我们在平台之间分发CLI,而无需额外的工程工作。

Go编译后的二进制文件与解释型语言相比,其性能优势也很明显。根据计算机基准测试结果,Go的速度远胜Python。

许多其他的基础设施CLI工具也是用Go编写的,这绝非偶然,具体的理由请参照下面的第三点。

Go的生态系统非常适合基础设施项目

开源的好处之一在于,你可以向自己欣赏的项目学习。例如,Cortex存在于Kubernetes的生态系统中,而Kubernetes本身也是用Go编写。我们很幸运能够借鉴这个生态系统中许多出色的开源项目,其中包括:

  • kubectl:Kubernetes CLI

  • minikube:一种在本地运行Kubernetes的工具

  • helm:Kubernetes软件包管理工具

  • kops:管理生产Kubernetes的工具

  • eksctl:亚马逊EKS的官方CLI

上述这些工具都是Kubernetes项目,而且都是用Go语言编写的。如果你仔细查看CockroachDB和Hashicorp的基础设施项目(包括Vault、Nomad、Terraform、Consul和Packer),就会发现它们统统是用Go语言编写的。

Go在基础架构领域的流行还有另一个影响,那就是大多数对基础架构感兴趣的工程师都很熟悉Go。所以,很容易吸引到这些工程师。我们公司最优秀的一位工程师就是通过AngelList找到我们的,我们很幸运他找到了我们。

Go语言编程是一种享受

我们使用Go构建Cortex的最后一个理由就是,我们很享受Go语言编程。

相对于Python,Go的入门有点艰难。但是,Go的宽容性可以为大型项目带来愉悦感。我们在测试软件上非常严格,但是静态输入和编译(对于初学者来说Go的两大难题)对我们来说就像是防护栏,帮助我们编写(相对而言)没有bug的代码。

你可能会说其他语言有不同的优势,但总的来说,Go能够最大限度地满足我们的技术和美学需求。

Python适用于机器学习,而Go适用于基础架构

我们也很喜欢Python,它在Cortex中占有一席之地,尤其是在处理推理方面。

Cortex服务于TensorFlow、PyTorch、scikit-learn以及其他Python模型,这意味着与模型的接口以及推理之前和之后的处理均在Python中完成。虽然Python代码经过打包部署到Docker容器中,但这些容器是由Go编写的代码编排的。

如果你有兴趣成为一名机器学习工程师,那么必须熟练掌握Python。但是,如果你对机器学习的基础架构感兴趣,则应该认真考虑Go。

原文:https://towardsdatascience.com/why-were-writing-machine-learning-infrastructure-in-go-not-python-38d6a37e2d76

本文为 CSDN 翻译,转载请注明来源出处。

热 文 推 荐 

台积电否认受美国施压去建厂;微信公众号文章可发放定制红包封面;Git v2.25.0 发布 | 极客头条

滴滴章文嵩:一个人的 20 年开源热情和国内互联网开源运动

揭秘 IPython 的 5 种最佳调试方法

别让腾讯“科技向善”太孤独!

为什么 k8s 在阿里能成功?| 问底中国 IT 技术演进

170个新项目,579个活跃代码仓库,Facebook开源年度回顾

掌握 8 种语言、被阿里点赞,这名德国程序员简直开挂了!

K8s 实践 | 如何解决多租户集群的安全隔离问题?

你点的每个“在看”,我都认真当成了喜欢

发布了1648 篇原创文章 · 获赞 4万+ · 访问量 1371万+

Guess you like

Origin blog.csdn.net/csdnnews/article/details/104035584