Why
使用Mathematica + Python web framework提供对外的服务平台,由于机器上运行的都是AARCH64系统,而ARM Mathematica目前只支持32位的v6 v7,需要在aarch64上增加支持armhf v6 v7的运行时库。
Small TIPS
为了能够在Ubuntu 20.04 aarch64 系统上运行Mathematica ARM 32Bit,查阅了很多相关资料,最后试验成功,可以通过以下方式在aarch64系统上运行32位的Mathematica。
最主要的就是这一行:dpkg –add-architecture armhf 添加armhf源,后面就是安装对应的armhf libc libc++ zlib。
Mathematica 的相关程式安装包在这里
FROM ubuntu:20.04
RUN apt-get update
RUN dpkg --add-architecture armhf
RUN apt-get update
RUN apt-get install libc6-dev:armhf libstdc++-9-dev:armhf zlib1g-dev:armhf
COPY ./ /tmp/
WORKDIR /tmp
RUN apt install ./wolframscript_1.4.0+2020081702_armhf.deb -y
RUN apt install ./wolfram-engine_12.1.1+2020081901_armhf -y
WORKDIR /
Python Web and Wolfram Backend Demo
对应于Mathematica armhf位版本,安装gcc和g++都为armhf版本,所以我们安装的Python和Python Modules也需要对应到armhf。
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 ./get-pip.py
可能存在某些依赖未安装,那就需要apt-get download 安装包,然后手动安装python modules依赖。
pip3 install wolframclient
pip3 install wolframwebengine
依赖列表:
aiohttp==3.6.2
async-timeout==3.0.1
attrs==20.1.0
certifi==2020.6.20
chardet==3.0.4
idna==2.10
multidict==4.7.3
numpy==1.17.4
oauthlib==3.1.0
pytz==2020.1
pyzmq==18.1.1
requests==2.24.0
urllib3==1.25.10
wolframclient==1.1.4
wolframwebengine==1.0.2
yarl==1.5.1
错误
安装过程中,因为我们的平台是aarch64,而编译器采用的是armhf,所以可能会遇到如下错误。
File "/usr/local/lib/python3.8/dist-packages/wheel/bdist_wheel.py", line 278, in get
_tag
assert tag in supported_tags, "would build wheel with unsupported tag {}".format(t
ag)
AssertionError: would build wheel with unsupported tag ('cp38', 'cp38', 'linux_aarch64
')
----------------------------------------
ERROR: Failed building wheel for yarl
Failed to build yarl
ERROR: Could not build wheels for yarl which use PEP 517 and cannot be installed directl
y
解决的方法就是下载源码包,然后通过python3 setup.py install安装。
Demo
git clone https://github.com/WolframResearch/WolframWebEngineForPython.git
python3 -m wolframwebengine --demo --kernel /opt/Wolfram/WolframEngine/12.1/Executables/WolframKernel --domain 0.0.0.0
最后只要把官方的demo跑通,我们在aarch64上构建的mathematica web就完成了。
Wolfram NetModel Server
按照上述测试部署之后,我们就可以自己开发和托管Wolfram NetModel Web服务了。
我们会把训练完成的深度学习模型运行在Raspberry pi 4集群上,然后通过Cloudflare Argo将流量引导到我们的集群上,对外暴露我们的模型接口。
这样我们就能基于Wolfram Neural Network完整实现从模型设计->模型开发->模型训练->上线的整个流程。
相关命令
获取argo连接证书: cloudflared tunnel login
测试连通性: cloudflared –hostname model.cineneural.com –hello-world
对外公开web: cloudflared tunnel –hostname model.cineneural.com http://192.168.1.114:18000
即可访问运行在内网的服务model.cineneural.com
关于Cloudflare Argo的相关资料: