Disclaimer: The following is my personal opinion. If you have different opinions, please feel free to discuss them in the comments section. Thanks to reviewCopy the code

@all Developer, if you are going to study deep learning and improve your abilities, I suggest you start learning Swift. (Because Swift is the best language in the world, just kidding. 😆 😆 😆)

When programmers hear Swift, they probably think of Apple , and they probably think of app development for iOS or MacOS. If you’re looking into deep learning, you’ve probably heard of Swift’s version of TensorFlow. You may be wondering, “Why did Google create TensorFlow for Swift? Why add another language when you already have Python and C++?”

In this article, I’ll answer that question and outline why you should be aware of TensorFlow for Swift and the Swift language itself. I’m not going to provide a detailed explanation in the text, but I’ll provide plenty of links for you to dig into if you’re interested in the topic.

1. Swift has strong backing

Swift was created by Chris Lattner while working at Apple. Currently, Chris Lattner works at Google Brain, one of the most advanced ai research groups in the world. The fact that Swift’s founder now works in a lab that studies deep learning suggests this is a major project.

Some time ago, Google realized that while Python is a great language, it still has limitations that are hard to overcome. TensorFlow needed a new language, and after a long period of deliberation, it fell to Swift. I’m not going to go into all the details, but you can read this document for yourself, which describes Python’s shortcomings, considerations for other languages, and the eventual selection of Swift.

2. TensorFlow for Swift is more than just a code base

TensorFlow for Swift is not just TensorFlow in another language.

In essence, it is another branch of the Swift language (just like creating branch on Git). This means that The Swift version of TensorFlow is not a code base, but a language in its own right, with built-in functionality that supports all the functionality required by TensorFlow.

The Swift version of TensorFlow, for example, has a very powerful automatic differential system, which is the foundation needed for deep learning to calculate gradients. By contrast, Python’s automatic differential system is not a core part of the language. Some of the features originally developed for the Swift version of TensorFlow were later integrated into the Swift language itself.

Swift is very fast

I was surprised when I first learned that Swift could run as fast as C code. I know THAT C is highly optimized and can achieve very high speeds, but this comes at the expense of micromemory management, so C is not memory safe. In addition, C is not a very easy language to learn.

Today, Swift’s numerical calculations are as fast as C, without memory security issues, and easier to learn. The LLVM compiler behind Swift is very powerful and has very efficient optimizations to ensure that code runs quickly.

4. You can use Python, C, and C++ code in Swift

Because Swift’s machine learning is just getting started, Swift’s machine learning library is small. However, you don’t have to worry, as Swift works well with Python. You just need to import the Python library into Swift, and you’re good to go. At the same time, you can import C and C++ libraries into Swift (for C++, you need to make sure that the header files are written in pure C with no C++ features).

In summary, if you need a specific feature that is not already implemented in Swift, you can import the corresponding Python, C, or C++ package. This is insane!

5. Swift can also go deep

If you’ve ever used TensorFlow, you’ve probably done it through a Python package. At the bottom, the Python version of TensorFlow is implemented in C. So when you call a function in TensorFlow, you’re bound to encounter some C code at some level. This means that you will encounter some limitations when looking at the source code. For example, if you want to see how convolution is implemented, you can’t see the Python code because it’s implemented in C.

However, things are different in Swift. Chris Lattner calls Swift “the syngrammatical sugar of LLVM [assembly language]”. This means that, in essence, Swift is very close to the hardware, with no additional layer written in C between Swift and the hardware. This also means that Swift code is very fast, as mentioned above.

As a result, developers can examine all code, whether it’s high-level code or very low-level code, without going deep into C.

6. Future development

Swift is just one part of Google’s deep learning innovation. There is another component that is very closely related: MLIR (Multi-Level Intermediate Representation). MLIR will be Google’s unified build infrastructure, allowing you to write code in Swift (or any other supported language) and compile to any supported hardware.

Currently, there are many compilers for different target hardware, but MLIR will change that. It will not only enable code reusability, but also allow you to write low-level components that the compiler can customize. It also allows researchers to apply machine learning to optimize low-level algorithms:

Although MLIR is a compiler for machine learning, we also see that it can apply machine learning techniques to the compiler itself! This is important because engineers can’t develop numerical libraries fast enough to keep up with machine learning models or hardware diversification.

Imagine being able to use deep learning to optimize the underlying memory slicing algorithm that processes the data (similar to what Halide is trying to accomplish). And, this is just the beginning, there are other creative applications of machine learning that can be used in compilers too!

conclusion

If you’re going to do deep learning, I suggest you start learning Swift. Swift has many advantages over Python. Google is investing heavily in Making Swift a key part of TensorFlow’s multi-tier infrastructure, and Swift is likely to become the language of deep learning. So get the ball rolling and start learning Swift as early as possible.