Skip to content
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

[Question] How to add bias after conv? #110

Closed
zhewenhu opened this issue Sep 10, 2024 · 4 comments
Closed

[Question] How to add bias after conv? #110

zhewenhu opened this issue Sep 10, 2024 · 4 comments

Comments

@zhewenhu
Copy link

zhewenhu commented Sep 10, 2024

Hi all, I am building the graph as in the image:
Image
The document suggests this graph is supported, but I got the seg fault at get_uid when doing graph->execute, could anyone help me to solve the problem?

I basically used the example here, but removed scaling. Here is my code:

graph = std::make_shared<fe::graph::Graph>();
graph->set_io_data_type(fe::DataType_t::FLOAT)
    .set_intermediate_data_type(fe::DataType_t::FLOAT)
    .set_compute_data_type(fe::DataType_t::FLOAT);

X = graph->tensor(fe::graph::Tensor_attributes()
                           .set_name("image")
                           .set_dim({n, c, h, w})
                           .set_stride({c * h * w, 1, c * w, c}));

W = graph->tensor(fe::graph::Tensor_attributes()
                           .set_name("filter")
                           .set_dim({k, c, r, s})
                           .set_stride({c * r * s, 1, r * s, s}));

conv_options =
    fe::graph::Conv_fprop_attributes().set_padding({1, 1}).set_stride({1, 1}).set_dilation({1, 1});
conv_output = graph->conv_fprop(X, W, conv_options);

B = graph->tensor(
            fe::graph::Tensor_attributes().set_name("bias").set_dim({1, k, 1, 1}).set_stride({k, 1, 1, 1}));
bias_options = fe::graph::Pointwise_attributes().set_mode(fe::PointwiseMode_t::ADD);
bias_output  = graph->pointwise(conv_output, B, bias_options);

gelu_options = fe::graph::Pointwise_attributes().set_mode(fe::PointwiseMode_t::GELU_FWD);
Y            = graph->pointwise(bias_output, gelu_options);
Y->set_output(true);

checkCudnnFeErr(graph1->validate(), "Graph validation failed");
checkCudnnFeErr(graph1->build_operation_graph(handle), "Building operation graph failed");
checkCudnnFeErr(graph1->create_execution_plans({fe::HeurMode_t::A}), "Creating execution plans failed");
checkCudnnFeErr(graph1->check_support(handle), "Checking graph support failed");
checkCudnnFeErr(graph1->build_plans(handle), "Building plans failed");

// initialize input, filter and output vector

std::unordered_map<std::shared_ptr<fe::graph::Tensor_attributes>, void*> variant_pack_1 = {
        {X, input}, {W, weight_devPtr}, {B, b_devPtr}, {Y, output_devPtr}};
@zhewenhu
Copy link
Author

I thought I solved it, but the problem remains, could someone help me with it?

@zhewenhu zhewenhu reopened this Sep 11, 2024
@gritukan
Copy link

Hi @zhewenhu,

Which values of n, c, h, w, k, r, and s do you use?

@zhewenhu
Copy link
Author

Hi @gritukan , my setting is n = 1, c = 1, h = 4, w = 4, k = 4, r = 3, s = 3;
I am doing a very simple test, here are the vectors I am testing

std::vector<float> x_values = {
    1, 2, 3, 4,
    5, 6, 7, 8,
    9, 10, 11, 12
    13, 14, 15, 16
    };

std::vector<float> w_values = {
     // First filter (3x3)
     1.0f, 0.0f, 1.0f,
     0.0f, 1.0f, 0.0f,
     1.0f, 0.0f, 1.0f,
     // Second filter (3x3)
     0.0f, 1.0f, 0.0f,
     1.0f, 0.0f, 1.0f,
     0.0f, 1.0f, 0.0f,
     // Third filter (3x3)
     1.0f, 1.0f, 1.0f,
     1.0f, 1.0f, 1.0f,
     1.0f, 1.0f, 1.0f,
     // Fourth filter (3x3 - all zeros)
     0.0f, 0.0f, 0.0f,
     0.0f, 0.0f, 0.0f,
     0.0f, 0.0f, 0.0f
     };

std::vector<float> x_values = {1, 1, 1, 1};

@Anerudhan
Copy link
Collaborator

Hi @zhewenhu
Can you tell me what error you are getting?

(backend/fe log will be useful)

Also, which architecture are you using?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants