Skip to content

Commit 1643c8b

Browse files
committed
Upload sections
1 parent 4bad198 commit 1643c8b

File tree

4 files changed

+302
-0
lines changed

4 files changed

+302
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Chapter Summary
2+
3+
1. In order to achieve a balance between usability and performance,
4+
modern machine learning systems utilize Python for frontend
5+
programming and C/C++ for backend programming.
6+
7+
2. It is expected from a machine learning framework to offer
8+
programming support for all aspects of a machine learning
9+
application workflow. This is usually delivered through high-level
10+
Python APIs, which facilitate activities such as data processing,
11+
model definition, loss function determination, model training, and
12+
model testing.
13+
14+
3. Large DNNs can be constructed by stacking neural network layers.
15+
16+
4. Various technologies are used to facilitate interoperability between
17+
Python and C, with pybind being a popular choice in machine learning
18+
frameworks.
19+
20+
5. Machine learning frameworks typically offer a variety of C/C++
21+
interfaces, allowing users to define and register operators
22+
implemented in C++. These operators enable users to create various
23+
framework extensions, such as high-performance models, data
24+
processing functions, and optimizers.

chapter_programming_model/Index.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Programming Model
2+
3+
Machine learning frameworks comprise various components that facilitate
4+
the efficient development of algorithms, data processing, model
5+
deployment, performance optimization, and hardware acceleration. When
6+
designing the application programming interfaces (APIs) for these
7+
components, a key consideration is striking the right balance between
8+
framework performance and usability. To achieve optimal performance,
9+
developers utilize C or C++, as these programming languages enable
10+
efficient invocation of the APIs provided by the operating system and
11+
hardware accelerators.
12+
13+
Regarding usability, machine learning framework users, including data
14+
scientists, biologists, chemists, and physicists, often possess strong
15+
industrial backgrounds and are skilled in using high-level scripting
16+
languages like Python, Matlab, R, and Julia. While these languages offer
17+
remarkable programming usability, they lack deep optimization
18+
capabilities for underlying hardware or operating systems compared to C
19+
and C++. Therefore, the core design objective of machine learning
20+
frameworks encompasses two aspects: providing easy-to-use APIs for
21+
implementing algorithms using high-level languages like Python, and
22+
providing low-level APIs centered around C and C++ to assist framework
23+
developers in implementing numerous high-performance components and
24+
efficiently executing them on hardware. This chapter describes
25+
strategies for achieving this design objective.
26+
27+
The chapter aims to achieve the following learning objectives:
28+
29+
1. Understanding the workflows and programming principles of machine
30+
learning frameworks.
31+
32+
2. Understanding the design of neural network models and layers.
33+
34+
3. Understanding how machine learning frameworks bridge Python and
35+
C/C++ functions.
36+
37+
4. Understanding the support for functional programming in machine
38+
learning frameworks.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Overview
2+
3+
With the advent of machine learning systems, the design of user-friendly
4+
and high-performance APIs has become a paramount concern for system
5+
designers. In the early stages of machine learning frameworks (as
6+
depicted in Figure :numref:`ch03/framework_development_history`, developers often
7+
opted for high-level programming languages like Lua (Torch) and Python
8+
(Theano) to write machine learning programs. These frameworks offered
9+
essential functions, including model definition and automatic
10+
differentiation, which are integral to machine learning. They were
11+
particularly well-suited for creating small-scale machine learning
12+
applications targeted toward scientific research purposes.
13+
14+
<figure id="fig:ch03/framework_development_history">
15+
<embed src="../img/ch03/framework_development_history.pdf" />
16+
<figcaption> Evolution of Machine Learning Programming Frameworks: A
17+
Historical Perspective</figcaption>
18+
</figure>
19+
20+
The rapid advancement of deep neural networks (DNNs) since 2011 has
21+
sparked groundbreaking achievements in various AI application domains,
22+
such as computer vision, speech recognition, and natural language
23+
processing. However, training DNNs requires substantial computational
24+
power. Unfortunately, earlier frameworks like Torch (primarily using
25+
Lua) and Theano (mainly using Python) were unable to fully harness this
26+
computing power. On the other hand, general-purpose APIs like CUDA C for
27+
computational accelerators such as NVIDIA GPUs have become increasingly
28+
mature, and multi-thread libraries like POSIX Threads built on CPU
29+
multi-core technology have gained popularity among developers.
30+
Consequently, many machine learning users sought to develop
31+
high-performance deep learning applications utilizing C/C++. These
32+
requirements led to the emergence of frameworks like Caffe, which
33+
employed C/C++ as their core APIs.
34+
35+
However, customization of machine learning models is often necessary to
36+
suit specific deployment scenarios, data types, identification tasks,
37+
and so on. This customization typically falls on the shoulders of AI
38+
application developers, who may come from diverse backgrounds and may
39+
not fully leverage the capabilities of C/C++. This became a significant
40+
bottleneck that hindered the widespread adoption of programming
41+
frameworks like Caffe, which heavily relied on C/C++.
42+
43+
In late 2015, Google introduced TensorFlow, which revolutionized the
44+
landscape. In contrast to Torch, TensorFlow adopted a design where the
45+
frontend and backend were relatively independent. The frontend,
46+
presented to users, utilized the high-level programming language Python,
47+
while the high-performance backend was implemented in C/C++. TensorFlow
48+
provided numerous Python-based frontend APIs, gaining wide acceptance
49+
among data scientists and machine learning researchers. It seamlessly
50+
integrated into Python-dominated big data ecosystems, benefiting from
51+
various big data development libraries such as NumPy, Pandas, SciPy,
52+
Matplotlib, and PySpark. Python's exceptional interoperability with
53+
C/C++, as demonstrated in multiple Python libraries, further enhanced
54+
TensorFlow's appeal. Consequently, TensorFlow combined the flexibility
55+
and ecosystem of Python with high-performance capabilities offered by
56+
its C/C++ backend. This design philosophy was inherited by subsequent
57+
frameworks like PyTorch, MindSpore, and PaddlePaddle.
58+
59+
Subsequently, as observed globally, prominent enterprises started
60+
favoring open-source machine learning frameworks, leading to the
61+
emergence of Keras and TensorLayerX. These high-level libraries
62+
significantly expedited the development of machine learning
63+
applications. They provided Python APIs that allowed quick importing of
64+
existing models, and these high-level APIs were decoupled from the
65+
intricate implementation details of specific machine learning
66+
frameworks. As a result, Keras and TensorLayerX could be utilized across
67+
different machine learning frameworks.
68+
69+
While deep neural networks continued to evolve, new challenges surfaced
70+
regarding the APIs of machine learning frameworks. Around 2020, novel
71+
frameworks like MindSpore and JAX emerged to tackle these challenges.
72+
MindSpore, in addition to inheriting the hybrid interfaces (Python and
73+
C/C++) from TensorFlow and PyTorch, expanded the scope of machine
74+
learning programming models. This expansion facilitated efficient
75+
support for a diverse range of AI backend chips, including NVIDIA GPU,
76+
Huawei Ascend , and ARM. Consequently, machine learning applications can
77+
be swiftly deployed across a wide array of heterogeneous devices.
78+
79+
Simultaneously, the proliferation of ultra-large datasets and
80+
ultra-large DNNs necessitated distributed execution as a fundamental
81+
design requirement for machine learning programming frameworks. However,
82+
implementing distributed execution in TensorFlow and PyTorch required
83+
developers to write substantial amounts of code for allocating datasets
84+
and DNNs across distributed nodes. Yet, many AI developers are not
85+
well-versed in distributed programming. In this regard, JAX and
86+
MindSpore significantly improves the situation by enabling the seamless
87+
execution of programs on a single node across various other nodes.

0 commit comments

Comments
 (0)