-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathml-pipeline-mars-pytorch.rst
More file actions
211 lines (168 loc) · 10.2 KB
/
Copy pathml-pipeline-mars-pytorch.rst
File metadata and controls
211 lines (168 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
Machine learning with Vineyard on Kubernetes
--------------------------------------------
In this demonstration, we will build a fraudulent transaction classifier for
fraudulent transaction data. The process consists of the following
three main steps:
- :code:`prepare-data`: Utilize Vineyard to read and store data in a distributed manner.
- :code:`process-data`: Employ Mars to process the data across multiple nodes.
- :code:`train-data`: Use Pytorch to train the model on the distributed data.
We have three tables: user table, product table, and transaction table.
The user and product tables primarily contain user and product IDs, along with
their respective ``Feature`` vectors. Each record in the transaction table indicates
a user purchasing a product, with a ``Fraud`` label identifying whether the
transaction is fraudulent. Additional features related to these transactions are also
stored in the transaction table. You can find the three tables in the `dataset repo`_.
Follow the steps below to reproduce the demonstration. First, create a vineyard cluster
with 3 worker nodes.
.. code:: bash
$ cd k8s && make -C k8s/test/e2e install-vineyard-cluster
.. admonition:: Expected output
:class: admonition-details
.. code:: bash
the kubeconfig path is /tmp/e2e-k8s.config
Creating the kind cluster with local registry
a16c878c5091c1e5c9eff0a1fca065665f47edb4c8c75408b3d33e22f0ec0d05
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.24.0) 🖼
✓ Preparing nodes 📦 📦 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind --kubeconfig /tmp/e2e-k8s.config
Thanks for using kind! 😊
configmap/local-registry-hosting created
Installing vineyard-operator...
The push refers to repository [localhost:5001/vineyard-operator]
c3a672704524: Pushed
b14a7037d2e7: Pushed
8d7366c22fd8: Pushed
latest: digest: sha256:ea06c833351f19c5db28163406c55e2108676c27fdafea7652500c55ce333b9d size: 946
make[1]: Entering directory '/opt/caoye/v6d/k8s'
go: creating new go.mod: module tmp
/home/gsbot/go/bin/controller-gen rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases
cd config/manager && /usr/local/bin/kustomize edit set image controller=localhost:5001/vineyard-operator:latest
/usr/local/bin/kustomize build config/default | kubectl apply -f -
namespace/vineyard-system created
customresourcedefinition.apiextensions.k8s.io/backups.k8s.v6d.io created
customresourcedefinition.apiextensions.k8s.io/globalobjects.k8s.v6d.io created
customresourcedefinition.apiextensions.k8s.io/localobjects.k8s.v6d.io created
customresourcedefinition.apiextensions.k8s.io/operations.k8s.v6d.io created
customresourcedefinition.apiextensions.k8s.io/recovers.k8s.v6d.io created
customresourcedefinition.apiextensions.k8s.io/sidecars.k8s.v6d.io created
customresourcedefinition.apiextensions.k8s.io/vineyardds.k8s.v6d.io created
serviceaccount/vineyard-manager created
role.rbac.authorization.k8s.io/vineyard-leader-election-role created
clusterrole.rbac.authorization.k8s.io/vineyard-manager-role created
clusterrole.rbac.authorization.k8s.io/vineyard-metrics-reader created
clusterrole.rbac.authorization.k8s.io/vineyard-proxy-role created
clusterrole.rbac.authorization.k8s.io/vineyard-scheduler-plugin-role created
rolebinding.rbac.authorization.k8s.io/vineyard-leader-election-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/vineyard-kube-scheduler-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/vineyard-manager-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/vineyard-proxy-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/vineyard-scheduler-plugin-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/vineyard-scheduler-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/vineyard-volume-scheduler-rolebinding created
service/vineyard-controller-manager-metrics-service created
service/vineyard-webhook-service created
deployment.apps/vineyard-controller-manager created
mutatingwebhookconfiguration.admissionregistration.k8s.io/vineyard-mutating-webhook-configuration created
validatingwebhookconfiguration.admissionregistration.k8s.io/vineyard-validating-webhook-configuration created
make[1]: Leaving directory '/opt/caoye/v6d/k8s'
deployment.apps/vineyard-controller-manager condition met
Vineyard-Operator Ready
Installing vineyard cluster...
vineyardd.k8s.v6d.io/vineyardd-sample created
vineyardd.k8s.v6d.io/vineyardd-sample condition met
Vineyard cluster Ready
Verify that all Vineyard pods are running.
.. code:: bash
$ KUBECONFIG=/tmp/e2e-k8s.config kubectl get pod -n vineyard-system
.. admonition:: Expected output
:class: admonition-details
.. code:: bash
NAME READY STATUS RESTARTS AGE
etcd0 1/1 Running 0 68s
etcd1 1/1 Running 0 68s
etcd2 1/1 Running 0 68s
vineyard-controller-manager-7f569b57c5-46tgq 2/2 Running 0 92s
vineyardd-sample-6ffcb96cbc-gs2v9 1/1 Running 0 67s
vineyardd-sample-6ffcb96cbc-n59gg 1/1 Running 0 67s
vineyardd-sample-6ffcb96cbc-xwpzd 1/1 Running 0 67s
First, let's prepare the dataset and download it into the kind worker nodes as follows.
.. code:: bash
$ worker=($(docker ps | grep kind-worker | awk -F ' ' '{print $1}'))
$ for c in ${worker[@]}; do \
docker exec $c sh -c "\
mkdir -p /datasets; \
cd /datasets/; \
curl -OL https://raw.githubusercontent.com/GraphScope/gstest/master/vineyard-mars-showcase-dataset/{item,txn,user}.csv" \
done
The `prepare-data` job primarily reads the datasets and distributes them across different
Vineyard nodes. For more information, please refer to the `prepare data code`_. To apply
the job, follow the steps below:
.. note::
The `prepare-data` job needs to exec into the other pods. Therefore, you need to
create a service account and bind it to the role under the namespace.
Please make sure you can have permission to create the following role.
.. code:: text
- apiGroups: [""]
resources: ["pods", "pods/log", "pods/exec"]
verbs: ["get", "patch", "delete", "create", "watch", "list"]
.. code:: bash
$ kubectl create ns vineyard-job && \
kubectl apply -f showcase/vineyard-mars-pytorch/prepare-data/resources && \
kubectl wait job -n vineyard-job -l app=prepare-data --for condition=complete --timeout=1200s
.. admonition:: Expected output
:class: admonition-details
.. code:: bash
namespace/vineyard-job created
clusterrolebinding.rbac.authorization.k8s.io/prepare-data-rolebinding created
clusterrole.rbac.authorization.k8s.io/prepare-data-role created
job.batch/prepare-data created
serviceaccount/prepare-data created
job.batch/prepare-data condition met
.. note::
The `process-data` job needs to create a new namespace and deploy several kubernetes
resources in it. Please make sure you can have permission to create the following role.
.. code:: text
- apiGroups: [""]
resources: ["pods", "pods/exec", "pods/log", "endpoints", "services"]
verbs: ["get", "patch", "delete", "create", "watch", "list"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get", "create", "delete"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list"]
- apiGroups: ["rbac.authorization.k8s.io"]
resources: ["roles", "rolebindings"]
verbs: ["patch", "get", "create", "delete"]
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["create"]
Notice, the `process-data` job will require lots of permissions to deal
kubernetes resources, so please check the image of `process-data` job
if it is an official one.
The `prepare-data` job creates numerous dataframes in Vineyard. To combine these dataframes,
we use the appropriate join method in `mars`_. For more details, refer to the `process data
code`_. Apply the `process-data` job as follows:
.. code:: bash
$ kubectl apply -f showcase/vineyard-mars-pytorch/process-data/resources && \
kubectl wait job -n vineyard-job -l app=process-data --for condition=complete --timeout=1200s
Finally, apply the `train-data` job to obtain the fraudulent transaction classifier. You can
also view the `train data code`_.
.. code:: bash
$ kubectl apply -f k8s/showcase/vineyard-mars-pytorch/train-data/resources && \
kubectl wait pods -n vineyard-job -l app=train-data --for condition=Ready --timeout=1200s
If any of the above steps fail, please refer to the `mars showcase e2e test`_ for further guidance.
.. _mars: https://github.com/mars-project/mars
.. _mars showcase e2e test: https://github.com/v6d-io/v6d/blob/main/k8s/test/e2e/mars-examples/e2e.yaml
.. _dataset repo: https://github.com/GraphScope/gstest/tree/master/vineyard-mars-showcase-dataset
.. _prepare data code: https://github.com/v6d-io/v6d/blob/main/k8s/examples/vineyard-mars-pytorch/prepare-data/prepare-data.py
.. _process data code: https://github.com/v6d-io/v6d/blob/main/k8s/examples/vineyard-mars-pytorch/process-data/process-data.py
.. _train data code: https://github.com/v6d-io/v6d/blob/main/k8s/examples/vineyard-mars-pytorch/train-data/train-data.py