MXNet
首先
在incubator-mxnet/example/image-classification/
中运行
python ../../tools/launch.py -n 2 -s 1 --launcher ssh -H hosts \
--sync-dst-dir /home/xugb/image-classification_test/ \
python train_mnist.py --network lenet --kv-store dist_sync
即python调用incubator-mxnet/tools/launch.py
,同时传入参数
agrs | function |
---|---|
-n 2 | |
-s 1 | |
--launcher ssh | |
-H hosts | |
--sync-dst-dir /home/xugb/image-classification_test/ | |
python train_mnist.py --network lenet --kv-store dist_sync |
之后解析这些参数
-n 2 -s 1 --launcher ssh -H hosts --sync-dst-dir /home/xugb/image-classification_test/
和
python train_mnist.py --network lenet --kv-store dist_sync
并且根据这些配置,调用相应函数。
连接各主机
incubator-mxnet/3rdparty/dmlc-core/tracker/dmlc_tracker/ssh.py
incubator-mxnet/3rdparty/dmlc-core/tracker/dmlc_tracker/tracker.py
初始化PSTracker
作为PS的控制节点。然后返回调用ssh.py
的函数,ssh连接其他server和worker,并运行python train_mnist.py --network lenet --kv-store dist_sync
,环境和DMLC_ROLE
都被传过去了。然后当前进程的控制权给PS scheduler。
各个节点的运行
incubator-mxnet/example/image-classification/train_imagenet.py
根据传入的args,动态调用
incubator-mxnet/example/image-classification/symbols/lenet.py
,
从incubator-mxnet/example/image-classification/common/date.py/
得到data,
得到的参数再传入incubator-mxnet/example/image-classification/common/fit.py
的fit函数。
fit则再调用incubator-mxnet/python/mxnet/model/module.py
(继承incubator-mxnet/python/mxnet/model/base_module.py
),接着看父类base_module的fit的文档
fit.py
-
incubator-mxnet/example/image-classification/common/fit.py
- kvstore
- 首先
kv = mx.kvstore.create(args.kv_store)
,来自incubator-mxnet/python/mxnet/kvstore.py
的create()
函数 - 调用c的API,
include/mxnet/c_api.h
,src/c_api/c_api.cc
- 首先
- kv.rank
- kv.rank在
python/mxnet/kvstore.py的rank()
- kv.rank在
- model.fit() 传入kv
- kvstore
module.py
-
python/mxnet/module/module.py
继承base_module.py
,在BaseModule
的fit
- 在
BaseModule
的fit
中- init_params
- init_optimizer
- update
- optimizer
- update在
module.py
具体实现了,- 调用了
python/mxnet/model.py
的_update_params_on_kvstore
- kvstore.push(name, grad_list, priority=-index) # push grad
- kvstore.pull(name, arg_list, priority=-index) # pull weight
- 于是到了
python/mxnet/kvstore.py
的push
和pull
函数。-
python/mxnet/kvstore.py
的push
和pull
函数即由src/c_api
和include/mxnet/c_api.h
的MXKVStorePush
、MXKVStorePushEx
、MXKVStorePull
、MXKVStorePullEx
实现-
c_api
其实是为了给其他语言提供统一接口,本质也是在调用src/kvstore
下的c语言实现的kvstore。
-
-
- 调用了
-
python/mxnet/optimizer.py
的update
决定了如何利用grad更新weight
c++的kvstore
- 在
src/kvstore/kvstore.cc
下,kvstore根据dist_async
来判断创建KVStoreDist
或者KVStoreLocal
-
src/kvstore/kvstore_dist.h
是继承kvstore_local.h
的,并重新实现InitImpl
、PullImpl
和PushImpl
等 -
kvstore_dist.h
和kvstore_dist_server.h
用到pslite -
PushImpl
-
Push_
-
PushDefault
-
ps::KVWorker<real_t>*
的ps_worker_->ZPush()
。在ps-list/include/ps/kv_app.h
-
KVWorker<Val>::Send()
调用Postoffice::Get()->van()->Send(msg);
-
Van::Send(const Message& msg)
调用zmq_van.h
的SendMsg(msg)
,用zmq_van.h
的senders_
来得到socket。而zmq_van.h
的senders_
由void Connect(const Node& node)
连接而来
-
-
-
-
-
-
PullImpl
- ``
cppkafka
librdkafka
在src/rdkafka_transport.c
有rd_kafka_transport_t *rd_kafka_transport_connect
用broker thread建立socket连接。
网友评论