Install
1 | cargo |
Commands
Open Session
1 | zellij -s {sessioin-name} # open new session with name |
Attach
1 | zellij a {session-name} |
Tips
Copy Contest
1 | enter search mode -> edit |
Troubleshotting
Shortkey Conflict
1 | enter locked mode |
1 | cargo |
Open Session
1 | zellij -s {sessioin-name} # open new session with name |
Attach
1 | zellij a {session-name} |
1 | enter search mode -> edit |
1 | enter locked mode |
报错信息
1 | 'xterm-kitty': unknown terminal type. |
解决方案
1 | append this into shell config file |
Arrow C++ 库由多个部分组成,每个部分完成不同的功能。
Memory management 抽象提供了统一的 API 来管理内存
Buffer 抽象表示物理数据的连续区域。
读写尽可能多的文件格式,比如 Parquet、CSV、Orc,以及 Arrow 专用的 Feather 格式。
文件系统抽象允许从不同的存储后端读取和写入数据,例如本地文件系统或 S3 存储桶
FunctionRegistry
)中,可以在其中按名称查找它们arrow::compute::CallFunctioni()
来调用arrow::compute::Add()
1 | arrow::compute::CallFunctioni("add", ...) 等价于 arrow::compute::Add(...) |
需要注意的是,一些函数还需要特定类型的参数(Options)。
1 | ScalarAggregateOptions scalar_aggregate_options; |
functions 可能会对输入进行隐式转换。
如果一个 Function 不支持一个输入类型,会返回 TypeError Status。
标量聚合操作操作在 (Chunked)Array、Scalar,产生单个输出值。
具体的聚合方法看这里。
组聚合方法通常无法直接调用,通常作为 SQL 类型 group by
操作,详见这里。
这类方法接受 Array 和 Scalar 作为输入。对于一元输入,输入是什么类型,输出就是什么类型。
两元输入时有如下的语义(在其他领域有时称为 broadcasting
比如 Numpy)。
更多。
Acero 是一个流查询引擎,用来制定和执行计算。
Arrow 使用 ExecPlan 来表示计算,ExecPlan 以零个或多个 Stream 作为输入,但输出只有一个 Stream。Plan 描述了数据怎么被转换、传递。
Acero 处理流式数据,Compute 处理内存中的数据。
ExecNode 是 Acero 中最基础的概念,ExecNode 有零个或多个输入,零或一个输出。如果没有 Source,称其为源;如果没有输出,称其为 Sink。ExecNode 还有多种类型。
批量数据(Batches of Data)使用 ExecBatch 类来描述。ExecBatch 是一个二维结构,和 RecordBatch 很相似。可以有零个或多个列,每个列必须有相同的长度。
1 | exec_batch.length : 数据行度 (row) |
RecordBatch 和 ExecBatch 对 Arrays 和 Buffers 都有强所有权。把 RecordBatch 转换为 ExecBatch 总是零拷贝的。但是 ExecBatch 转换为 RecordBatch 时只有在无标量(Scalar) 时才是零拷贝。
ExecPlan 表示由 ExecNode 组成的图。一个合法的 ExecPlan 必须由一个 Source 节点,但技术上不需要有 Sink 节点。ExecPlan 包含所有节点共享的资源,以及工具方法来启动、停止节点的执行。ExecPlan 和 ExecNode 都与单个执行的生命周期相关联。它们有状态,预计不可重新启动。
Declaration 是 ExecNode 的蓝图。声明可以组合成一个图表,形成 ExecPlan 的蓝图。
Acero 的基础工作流如下。
Substrait 是创建 Plan (Graph of Declaration)的推荐机制,原因如下。
以编程方式创建执行计划比从 Substra 创建计划更简单。Declaration::Sequence()
可以更方便地创建处理序列。
arrow::Table
arrow::RecordBatchReader
ExecPlan::Validate
EexcPlan::StartProducing
ExecPlan::finished
用作数据源。
对数据进行计算、转换、重塑。
重新排序、组合或切片数据流。
Sink 节点会结束一个 Plan。通常不需要创建 Sink Node,会基于 DeclarationToXyz 方法选择。
PushGenerator
JoinType
KernelState
KernelContext
KernelInitArgs
ScalarKernel
1 | // Function 帮助类 |
所有神经网络模块的基类,自定义的模型也应把该类作为基类。
1 | forward(*input) : 定义每次调用时的计算逻辑,所有子类都应该重写 |
提供了一种简单的方式来按顺序堆叠神经网络的层,用于快速构建一个顺序的神经网络模型。在模型进行前向传播时,nn.Sequential
会按照层的顺序依次调用每个层的forward
方法,将前一层的输出作为下一层的输入,直到最后一层输出结果。
local_rank = torch.distributed.get_rank() % torch.cuda.device_count()
计算(在每个机器进程数一致时)metaspore.so
环境变量
1 | export REPOSITORY={hub-repo} |
构建 Dev 镜像(基础环境)
1 | DOCKER_BUILDKIT=1 docker build --network host --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} --build-arg RUNTIME=gpu -f docker/ubuntu20.04/Dockerfile_dev -t $REPOSITORY/metaspore-dev-gpu:${VERSION} . |
Serving
Training
Build 镜像(基于 Dev 镜像进行编译)
1 | DOCKER_BUILDKIT=1 docker build --network host --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} -f docker/ubuntu20.04/Dockerfile_training_build --build-arg DEV_IMAGE=$REPOSITORY/metaspore-dev-cpu:${VERSION} -t $REPOSITORY/metaspore-training-build:${VERSION} . |
Spark Training 镜像
1 | DOCKER_BUILDKIT=1 docker build --network host --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} -f docker/ubuntu20.04/Dockerfile_training_release --build-arg METASPORE_RELEASE=build --build-arg METASPORE_BUILD_IMAGE=$REPOSITORY/metaspore-training-build:${VERSION} -t $REPOSITORY/metaspore-training-release:${VERSION} --target release . |
Jupyter
1 | DOCKER_BUILDKIT=1 docker build --network host --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} -f docker/ubuntu20.04/Dockerfile_jupyter --build-arg RELEASE_IMAGE=$REPOSITORY/metaspore-training-release:${VERSION} -t $REPOSITORY/metaspore-training-jupyter:${VERSION} docker/ubuntu20.04 |
MetaSpore C++ 包含几个模块。
globals
hashmap
arrow
features
1 | embedding_size : 每个特征组的 embedding size |
初始化内容。
1 | PyTorchEstimator |
1 | PyTorchAgent |
FeatureComputeContext 和 FeatureComputeExecContext 都是在 cpp 文件中进行定义。
1 | EmbeddingBagModule -> torch.nn.Module |
1 | EmbeddingSumConcat -> EmbeddingOperator -> torch.nn.Module |
基于神经元模型,提出了感知机学习规则。感知机规则提出了一个可以自动学习的权重优化算法。
感知机算法步骤如下。
需要注意的是。
调用 CUDA 运行时 API 时,接口返回错误码。
1 | __host__ __device__ cudaError_t cudaGetDeviceCount ( int* count ); // 获取设备数量, 返回错误码 |
1 | __host__ __device__ const char* cudaGetErrorName ( cudaError_t error ); // 获取错误码的枚举名称 |
定义错误检查函数
1 | __host__ void error_check_entry() { |
核函数的返回值必须是 void。
1 | __host__ __device__ cudaError_t cudaGetLastError ( void ); // 返回最后一次错误码 |
1 | __global__ void kernel_error_entry() { |
1 | __host__ cudaError_t cudaEventCreate ( cudaEvent_t* event ); |
示例。
1 | cudaEvent_t start, end; |
error_check。
1 | __host__ __device__ cudaError_t error_check(cudaError_t err, const char *fn, int line) { |
nvprof 是评估 cuda 程序性能的工具。不过目前已经是过时的工具,不适用 compute capability >= 8.0 的设备。新设备适用 nsys 替代。
1 | nvprof {cuda-program} |
1 | nsys profile {cuda-program} # 运行并记录程序的 profile 到 nsys-rep 文件 |
运行时 API
1 | __host__ cudaError_t cudaGetDeviceProperties ( cudaDeviceProp* prop, int device ) |
1 | __host__ void PrintDeviceInfo() { |