Comments (4)
改一下fill_constant
算子的InferShape
方法后无Core dump
std::vector<shape_t> InferShapeForFillConstant(const std::vector<shape_t> &inputs_shape,
const framework::AttrMapType &attrs) {
CHECK(attrs.count("shape"));
auto shape = absl::get<std::vector<int>>(attrs.at("shape"));
// CHECK(!shape.empty()) << "shape attr is empty!";
if (shape.empty()) {
return {{1}};
}
return {shape};
}
但是会有新的错误,目测不是CINN的问题
I0331 12:09:30.874068 13931 build_cinn_pass.cc:682] --- [build_cinn_pass] detected 97 cinn supported subgraphs
Traceback (most recent call last):
File "examples/cylinder/3d_unsteady_discrete/baseline/cylinder3d_unsteady.py", line 172, in <module>
checkpoint_path=checkpoint_path + str(next_time) + "/")
File "/home/wengyu02/work/PaddleScience/paddlescience/solver/solver.py", line 167, in solve
num_epoch, bs, checkpoint_freq, checkpoint_path
File "/home/wengyu02/work/PaddleScience/paddlescience/solver/solver.py", line 645, in __solve_static
rslt = self.exe.run(compiled_program, feed=feeds, fetch_list=fetches)
File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/executor.py", line 1458, in run
use_prune=use_prune,
File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/executor.py", line 1661, in _run_impl
scope, list(feed.keys()), fetch_list, return_numpy
File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/executor.py", line 683, in run
scope, feed_names, fetch_list
NotImplementedError: In user code:
File "examples/cylinder/3d_unsteady_discrete/baseline/cylinder3d_unsteady.py", line 154, in <module>
solver = psci.solver.Solver(pde=pde_disc, algo=algo, opt=opt)
File "/home/wengyu02/work/PaddleScience/paddlescience/solver/solver.py", line 143, in __init__
self.__init_static()
File "/home/wengyu02/work/PaddleScience/paddlescience/solver/solver.py", line 584, in __init_static
self.opt.minimize(self.loss)
File "/usr/local/lib/python3.7/dist-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/dygraph/base.py", line 351, in _decorate_function
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/paddle/optimizer/optimizer.py", line 1436, in minimize
no_grad_set=no_grad_set,
File "/usr/local/lib/python3.7/dist-packages/paddle/optimizer/optimizer.py", line 1123, in backward
[loss], parameter_list, act_no_grad_set, callbacks
File "/usr/local/lib/python3.7/dist-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/wrapped_decorator.py", line 25, in __impl__
return wrapped_func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/framework.py", line 560, in __impl__
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/paddle/optimizer/optimizer.py", line 64, in append_backward_new
orig2prim(block)
File "/usr/local/lib/python3.7/dist-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/wrapped_decorator.py", line 25, in __impl__
return wrapped_func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/framework.py", line 560, in __impl__
return func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/paddle/incubate/autograd/primx.py", line 763, in orig2prim
_lower(block, reverse=False, blacklist=[])
File "/usr/local/lib/python3.7/dist-packages/paddle/incubate/autograd/primx.py", line 523, in _lower
attrs=attrs,
File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/framework.py", line 2980, in __init__
for frame in traceback.extract_stack():
UnimplementedError: Prim operator pow_p should not be excuted directly (at /home/wengyu02/work/Paddle/paddle/fluid/operators/prim_ops/pow_p_op.cc:30)
[operator < pow_p > error]
from cinn.
打印 log,发现部分算子缺失 shape 的数据:
ops {
outputs {
parameter: "Y"
arguments: "tmp_7"
}
type: "fill_constant_p"
attrs {
name: "dtype"
type: INT
i: 5
}
attrs {
name: "op_callstack"
type: STRINGS
strings: " File \"examples/cylinder/3d_unsteady_discrete/baseline/cylinder3d_unsteady.py\", line 154, in <module>"
strings: " solver = psci.solver.Solver(pde=pde_disc, algo=algo, opt=opt)"
strings: " File \"/PaddleScience/paddlescience/solver/solver.py\", line 143, in __init__"
strings: " self.__init_static()"
strings: " File \"/PaddleScience/paddlescience/solver/solver.py\", line 584, in __init_static"
strings: " self.opt.minimize(self.loss)"
strings: " File \"<decorator-gen-187>\", line 2, in minimize"
strings: " "
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/fluid/dygraph/base.py\", line 353, in _decorate_function"
strings: " return func(*args, **kwargs)"
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/optimizer/optimizer.py\", line 1436, in minimize"
strings: " no_grad_set=no_grad_set,"
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/optimizer/optimizer.py\", line 1123, in backward"
strings: " [loss], parameter_list, act_no_grad_set, callbacks"
strings: " File \"<decorator-gen-177>\", line 2, in append_backward_new"
strings: " "
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/fluid/wrapped_decorator.py\", line 25, in __impl__"
strings: " return wrapped_func(*args, **kwargs)"
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/fluid/framework.py\", line 626, in __impl__"
strings: " return func(*args, **kwargs)"
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/optimizer/optimizer.py\", line 64, in append_backward_new"
strings: " orig2prim(block)"
strings: " File \"<decorator-gen-220>\", line 2, in orig2prim"
strings: " "
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/fluid/wrapped_decorator.py\", line 25, in __impl__"
strings: " return wrapped_func(*args, **kwargs)"
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/fluid/framework.py\", line 626, in __impl__"
strings: " return func(*args, **kwargs)"
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/incubate/autograd/primx.py\", line 722, in orig2prim"
strings: " _lower(block, reverse=False, blacklist=[])"
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/incubate/autograd/primx.py\", line 523, in _lower"
strings: " attrs=attrs,"
strings: " File \"/usr/local/lib/python3.7/dist-packages/paddle/fluid/framework.py\", line 2977, in __init__"
strings: " for frame in traceback.extract_stack():"
}
attrs {
name: "op_device"
type: STRING
s: ""
}
attrs {
name: "op_namescope"
type: STRING
s: "/"
}
attrs {
name: "op_role"
type: INT
i: 0
}
attrs {
name: "op_role_var"
type: STRINGS
}
attrs {
name: "shape"
type: LONGS
!!!!!!! 这里缺失
}
attrs {
name: "value"
type: FLOAT
f: 2
}
attrs {
name: "with_quant_attr"
type: BOOLEAN
b: false
}
}
from cinn.
Paddle 里面是允许将 shape 设置为 [] 的,可能这个 shape 为 [] 的 var 是一个 placeholder
fill_constant_p 算子
没有提供实现,使用 prim2orig 的流程将它推给 paddle 执行(我猜
class FillConstantPrimOp : public framework::OperatorBase {
public:
FillConstantPrimOp(const std::string &type,
const framework::VariableNameMap &inputs,
const framework::VariableNameMap &outputs,
const framework::AttributeMap &attrs)
: framework::OperatorBase(type, inputs, outputs, attrs) {}
void RunImpl(const framework::Scope &scope,
const platform::Place &dev_place) const override {
PADDLE_THROW(platform::errors::Unimplemented(
"Prim operator fill_constant_p should not be excuted directly"));
}
};
fill_constant 算子
class FillConstantOp : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;
void InferShape(framework::InferShapeContext *ctx) const override {
OP_INOUT_CHECK(ctx->HasOutput("Out"), "Output", "Out", "FillConstant");
auto &shape = ctx->Attrs().Get<std::vector<int64_t>>("shape");
if (!ctx->HasInput("ShapeTensor") && !ctx->HasInputs("ShapeTensorList")) {
for (size_t i = 0; i < shape.size(); ++i) {
PADDLE_ENFORCE_GE(
shape[i],
0,
platform::errors::InvalidArgument(
"Each value of attribute 'shape' is expected to be no less "
"than 0. But received: shape[%u] = %d; shape = [%s].",
i,
shape[i],
phi::make_ddim(shape)));
}
}
if (shape.empty() && ctx->HasInput("ShapeTensor")) {
auto shape_dims = ctx->GetInputDim("ShapeTensor");
int num_ele = 1;
for (int i = 0; i < shape_dims.size(); ++i) {
num_ele *= shape_dims[i];
}
auto vec_dims = std::vector<int>(num_ele, -1);
ctx->SetOutputDim("Out", phi::make_ddim(vec_dims));
return;
}
ctx->SetOutputDim("Out", phi::make_ddim(shape));
}
protected:
phi::KernelKey GetKernelTypeForVar(
const std::string &var_name,
const phi::DenseTensor &tensor,
const phi::KernelKey &expected_kernel_type) const override {
if (var_name == "ShapeTensor" || var_name == "ShapeTensorList") {
return phi::KernelKey(phi::Backend::ALL_BACKEND,
expected_kernel_type.layout(),
expected_kernel_type.dtype());
} else {
return phi::KernelKey(
tensor.place(), tensor.layout(), expected_kernel_type.dtype());
}
}
phi::KernelKey GetExpectedKernelType(
const framework::ExecutionContext &ctx) const override {
auto input_data_type =
framework::proto::VarType::Type(ctx.Attr<int>("dtype"));
phi::KernelKey kt = phi::KernelKey(input_data_type, ctx.GetPlace());
// TODO(zyfncg) The force_cpu and place_type are conflicted, it's an issue
// left before, and we may merge them in the future.
// In order to invoke new fill_constant kernel, the place of OpKernelType
// will be setted by force_cpu and place_type here.
if (ctx.Attr<bool>("force_cpu")) {
kt.set_backend(phi::Backend::CPU);
}
auto place_type = ctx.Attr<int>("place_type");
if (place_type != -1) {
switch (place_type) {
case 0:
kt.set_backend(phi::Backend::CPU);
break;
case 1:
case 2:
kt.set_backend(phi::Backend::GPU);
break;
case 3:
kt.set_backend(phi::Backend::XPU);
break;
case 4:
kt.set_backend(phi::Backend::NPU);
break;
default:
PADDLE_THROW(platform::errors::Unimplemented(
"Could NOT determine the place of variable, place_type = %d .",
place_type));
}
}
return kt;
}
};
paddle 测试
使用空 shape [],会生成一个 0-D tensor
from cinn.
更新,把FLAGS_allow_cinn_ops
清空后(即允许使用CINN中的所有算子),就能正常跑通了
from cinn.
Related Issues (20)
- 【2022】CINN基础pass开发任务 HOT 2
- 【2022】CINN开发任务跟踪 HOT 19
- 部分算子的参数命名不规范 HOT 3
- 编译报错 libcinnapi.so HOT 1
- CINN 算子单测补充-ISSUES HOT 41
- CINN 算子单测问题总结
- 如何自动调优单算子
- computeAt and computeAt2 inconsistency
- support computeAt when forloops' range is consistent
- benchmark against tvm?
- Remove unnecessary null pointer checks HOT 4
- some images NOT issue HOT 2
- Will CINN support ONNX model? Thanks
- Compile Failed: cannot find -lpthreads HOT 3
- 生成的代码有2个`sync`?
- cmake 过程发生错误 HOT 8
- How to use ir::For::Make in Compute? HOT 5
- fatal error: cinn/backends/_generated1.cu No such file or directory HOT 5
- SetRandData<int> 返回是否应该针对整数张量进行初始化?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cinn.