-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function Argument #1064
Function Argument #1064
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good to me.
: buf_(buf), valueType_(valueType) {} | ||
|
||
BufferArg(const Matrix& matrix) | ||
: buf_((void*)matrix.getData()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use reinterpret_cast<void*>(matrix.getData())?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
BufferArg(const Matrix& matrix, const TensorShape& shape) | ||
: buf_((void*)matrix.getData()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as line 59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
BufferArg(const Vector& vector) | ||
: buf_((void*)vector.getData()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as line 59.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
BufferArg(const IVector& vector) | ||
: buf_((void*)vector.getData()), valueType_(VALUE_TYPE_INT32), shape_(1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
// sequence start positions in a mini-batch of sequences | ||
// shape_.ndims() == 1 | ||
// valueType_ = int32 | ||
// if a < b than value_.buf_[a] < value_.buf_[b] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a < b then value_.buf_[a] < value_.buf_[b]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
TensorShape(std::initializer_list<size_t> dims) { | ||
ndims_ = dims.size(); | ||
initDims(ndims_); | ||
std::copy(dims.begin(), dims.end(), dims_.begin()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use dims_.assign(dims.begin(), dims.end()) ?
|
||
template <DeviceType DType> | ||
void Function(const BufferArgs& arguments) { | ||
auto input = arguments[0].matrix<DType>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto input = arguments[0].matrix();
CHECK_EQ(inputs[0].shape()[0], outputs[0].shape()[0]); | ||
|
||
auto out_mat = outputs[0].matrix<Device>(); | ||
auto in_mat = inputs[0].matrix<Device>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto in_mat = inputs[0].matrix();
|
||
auto out_mat = outputs[0].matrix<Device>(); | ||
auto in_mat = inputs[0].matrix<Device>(); | ||
auto w_mat = !inputs[1].data() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto w_mat
auto w_grad_mat = !inputs[1].data() | ||
? typename Tensor<real, Device>::Matrix(nullptr, 0, 0) | ||
: inputs[1].matrix<Device>(); | ||
auto seq_vec = inputs[2].vector<int, Device>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto seq_vec
commit 57e2521 对BufferArg增加一个ArgType argType_属性,同时去掉了Function的inouts参数。 Function的inouts参数原先的设计是用来区分outputs参数的;对于有些情况,Function计算结果是直接赋值到output中(比如,PoolLayer::forward等),对于有些情况Function计算结果是累加到output上(比如,MixedLaye和Layer::backward计算等);对应assign to output的,是一个writeonly参数,用outputs来传参;add to output的,是一个read and write参数,用inouts来传参。 commit 57e2521修改的目的是,inouts参数的主要目的是为了描述Function计算结果是assign to output还是add to output,对BufferArg增加一个值为ASSIGN_TO或ADD_TO的属性更能清楚的表示这件事情;另外,对于有多个output的Function,可以对每个output单独标识ASSIGN_TO或ADD_TO的属性。 |
@hedaoyuan, LGTM, please make the checks pass and will approve it. |
* add sharding for gpt-3 * del debug * add sharding save model * update model save * fix seed func * set control in tensor parallel Co-authored-by: Zhong Hui <zhonghui.net@gmail.com>
This PR is to achieve argument types of the Functions.
关于Function的BufferArg描述见issue 892
基于BufferArgs参数类型的Function:: calc实现和调用方式如下: