CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Exceptions in backpropagation during sparse segmentation attempt

Open LowerySJ opened this issue 10 years ago • 9 comments

Hi, CNTK community. I'm trying to do sparse segmentation with a simple net using a slightly modified version of imagereader.

The network is simple for quick testing: 3 (conv/maxpooling) layers -> 1 fully connected layer -> resized -> square error criterion.

I'm getting a strange math library-related error when I try to train, and it has to do with backprop:

Starting minibatch loop.

About to throw exception 'cuDNN failure 8: CUDNN_STATUS_EXECUTION_FAILED ; GPU=0 ; hostname=EG-OPT-M25 ; expr=cudnnConvolutionBackwardFilter(*m_cudnn, &C::One, m_inT, ptr(in), m_outT, ptr(srcGrad), *m_conv, m_backFiltAlgo.Algo.algo, ptr(workspace), m_backFiltAlgo.Algo.memory, &C::One, *m_kernelT, ptr(kernelGrad))'
cuDNN failure 8: CUDNN_STATUS_EXECUTION_FAILED ; GPU=0 ; hostname=EG-OPT-M25 ; expr=cudnnConvolutionBackwardFilter(*m_cudnn, &C::One, m_inT, ptr(in), m_outT, ptr(srcGrad), *m_conv, m_backFiltAlgo.Algo.algo, ptr(workspace), m_backFiltAlgo.Algo.memory, &C::One, *m_kernelT, ptr(kernelGrad))


[CALL STACK]
    > CudaCall<enum cudnnStatus_t>  
    - Microsoft::MSR::CNTK::CuDnnConvolutionEngine<float>::  BackwardKernelCore
    - Microsoft::MSR::CNTK::ConvolutionEngine<float>::  BackwardKernel
    - Microsoft::MSR::CNTK::ConvolutionNode<float>::  BackpropTo
    - Microsoft::MSR::CNTK::ComputationNode<float>::  Backprop
    - Microsoft::MSR::CNTK::ComputationNetwork::PARTraversalFlowControlNode::  Backprop
    - Microsoft::MSR::CNTK::ComputationNetwork::  Backprop
    - Microsoft::MSR::CNTK::SGD<float>::  TrainOneEpoch
    - Microsoft::MSR::CNTK::SGD<float>::  TrainOrAdaptModel
    - Microsoft::MSR::CNTK::SGD<float>::  Train
    - DoTrain<Microsoft::MSR::CNTK::ConfigParameters,float>  
    - DoCommands<float>  
    - wmainOldCNTKConfig
    - wmain1
    - wmain
    - __tmainCRTStartup

EXCEPTION occurred: cuDNN failure 8: CUDNN_STATUS_EXECUTION_FAILED ; GPU=0 ; hostname=EG-OPT-M25 ; expr=cudnnConvolutionBackwardFilter(*m_cudnn, &C::One, m_inT, ptr(in), m_outT, ptr(srcGrad), *m_conv, m_backFiltAlgo.Algo.algo, ptr(workspace), m_backFiltAlgo.Algo.memory, &C::One, *m_kernelT, ptr(kernelGrad))

I've tried checking my network to see if it's not well-formed. It passes the validation step, in any case. Does reshaping hinder backpropagation? I was able to run the 04_DeConv MNIST example without errors, and it doesn't do reshaping. Any thoughts?

LowerySJ avatar Aug 18 '16 19:08 LowerySJ

Here are .cntk and brainscript macro files. Note: even though I'm working toward segmentation, I haven't figured out how to get the source code to pack an opencv image as an n x n x 1 data input. So, the segmentation mask/label is passed in as a greyscale n x n x 3 channel input for now, with corresponding changes to network.

Shared.bs.txt Seg4_redacted.cntk.txt

LowerySJ avatar Aug 18 '16 19:08 LowerySJ

Hmm, I don't have an answer. But this error comes from the NVidia library directly.

It could, however, be that the error happened in an earlier CUDA launch. CUDA cannot always report errors immediately, since it uses an asynchronous exection model. So to know that, could you please add a global configuration variable synchronizeCUDAKernelExecutions=true and try again? If the error happens in a different place, we will know.

frankseide avatar Aug 18 '16 19:08 frankseide

Frank, it's looking like that global configuration variable is only set in the wmainWithBS(...) routine. To get to that routine requires a command line argument other than "configFile=...", but looking over the wiki it's not clear what the new argument should be. The tutorials seem to all use "configFile=..."

        // detect legacy CNTK configuration
        bool isOldCNTKConfig = false;
        for (int i = 0; i < argc && !isOldCNTKConfig; i++)
            isOldCNTKConfig |= !_wcsnicmp(L"configFile=", argv[i], 11);

        if (isOldCNTKConfig)
            return wmainOldCNTKConfig(argc, argv);

        // run from BrainScript
        return wmainWithBS(argc, argv);

LowerySJ avatar Aug 18 '16 21:08 LowerySJ

Also, thanks for fast response!

LowerySJ avatar Aug 18 '16 21:08 LowerySJ

Ok, so I tried to flatten the segmentation mask to compare it to the output of the fully connected layer, rather than reshaping the output of fully connected layer to "fit" with the 3d segmentation mask. My hope was that the reshaping was interfering with the backpropagation to the convolution weights.

This did not help. I got the exact same error.

LowerySJ avatar Aug 18 '16 21:08 LowerySJ

OK, so it is this function. Could you paste the validation output from the log? Specifically the section that lists all the nodes with their dimensions? In the meantime, I will forward your request internally.

frankseide avatar Aug 19 '16 00:08 frankseide

Regarding the n x n x 1 data input you could try the following in your Seg4_redacted.cntk.txt file:

in line 46 maskLabel = ImageInput(ImageW, ImageH, 1) in line 113 ol = ReshapeDimension(h1, 1, (100:100:1)) in line 215 channels = 1

I'm not familiar with the SegReader though. You could also try to read in the image and the segmentation image using a composite reader that essentially uses the image reader twice:

    reader = [
        verbosity = 0
        randomize = true
        deserializers = (
        [
            type = "ImageDeserializer"
            module = "ImageReader"
            file = "YourImageMapFile"
            input = [
                rgbFeatures = [
                    transforms = (Scale, Flip, ...)
                ]
            ]
        ]:[
            type = "ImageDeserializer"
            module = "ImageReader"
            file = "YourMaskImageMapFile"
            input = [
                maskLabel = [
                    transforms = (Scale, Flip, ...)
                ]
            ]
        ]
        )
    ]

pkranen avatar Aug 19 '16 08:08 pkranen

PKranen, thanks for your advice. For my work, the transforms applied to each input/label stream have to be coordinated with one another to be useful and meaningful. As far as I know, there is not a way to coordinate transforms using the vanilla version of CNTK and composition of deserializers, so I modified ImageReader to suit my requirements.

FrankSeide, thanks for your help. Here is log file as text : Seg4_Train.log.txt.

I will be gone on vacation next week, so I won't respond immediately. Thanks and cheers

CNTKCommandTrainBegin: Train

Starting from checkpoint. Loading network from './Output/Models/Seg4.0'.

Post-processing network...

2 roots:
    mse = SquareError()
    ol = Reshape()

Validating network. 27 nodes to process in pass 1.

Validating --> maskLabel = InputValue() :  -> [100 x 100 x 3 x *]
Validating --> h1.W = LearnableParameter() :  -> [30000 x 11 x 11 x 64]
Validating --> conv3_act.w = LearnableParameter() :  -> [64 x 800]
Validating --> conv2_act.w = LearnableParameter() :  -> [32 x 800]
Validating --> conv1_act.w = LearnableParameter() :  -> [32 x 75]
Validating --> rgbFeatures = InputValue() :  -> [100 x 100 x 3 x *]
Validating --> conv1_act.c = Convolution (conv1_act.w, rgbFeatures) : [32 x 75], [100 x 100 x 3 x *] -> [100 x 100 x 32 x *]
Validating --> conv1_act.b = LearnableParameter() :  -> [1 x 1 x 32]
Validating --> conv1_act.out._ = Plus (conv1_act.c, conv1_act.b) : [100 x 100 x 32 x *], [1 x 1 x 32] -> [100 x 100 x 32 x *]
Validating --> conv1_act.out = RectifiedLinear (conv1_act.out._) : [100 x 100 x 32 x *] -> [100 x 100 x 32 x *]
Validating --> pool1 = MaxPooling (conv1_act.out) : [100 x 100 x 32 x *] -> [49 x 49 x 32 x *]
Validating --> conv2_act.c = Convolution (conv2_act.w, pool1) : [32 x 800], [49 x 49 x 32 x *] -> [49 x 49 x 32 x *]
Validating --> conv2_act.b = LearnableParameter() :  -> [1 x 1 x 32]
Validating --> conv2_act.out._ = Plus (conv2_act.c, conv2_act.b) : [49 x 49 x 32 x *], [1 x 1 x 32] -> [49 x 49 x 32 x *]
Validating --> conv2_act.out = RectifiedLinear (conv2_act.out._) : [49 x 49 x 32 x *] -> [49 x 49 x 32 x *]
Validating --> pool2 = MaxPooling (conv2_act.out) : [49 x 49 x 32 x *] -> [24 x 24 x 32 x *]
Validating --> conv3_act.c = Convolution (conv3_act.w, pool2) : [64 x 800], [24 x 24 x 32 x *] -> [24 x 24 x 64 x *]
Validating --> conv3_act.b = LearnableParameter() :  -> [1 x 1 x 64]
Validating --> conv3_act.out._ = Plus (conv3_act.c, conv3_act.b) : [24 x 24 x 64 x *], [1 x 1 x 64] -> [24 x 24 x 64 x *]
Validating --> conv3_act.out = RectifiedLinear (conv3_act.out._) : [24 x 24 x 64 x *] -> [24 x 24 x 64 x *]
Validating --> pool3 = MaxPooling (conv3_act.out) : [24 x 24 x 64 x *] -> [11 x 11 x 64 x *]
Validating --> h1.t = Times (h1.W, pool3) : [30000 x 11 x 11 x 64], [11 x 11 x 64 x *] -> [30000 x *]
Validating --> h1.b = LearnableParameter() :  -> [30000 x 1]
Validating --> h1.z = Plus (h1.t, h1.b) : [30000 x *], [30000 x 1] -> [30000 x 1 x *]
Validating --> h1.y = RectifiedLinear (h1.z) : [30000 x 1 x *] -> [30000 x 1 x *]
Validating --> ol = Reshape (h1.y) : [30000 x 1 x *] -> [100 x 100 x 3 x 1 x *]
Validating --> mse = SquareError (maskLabel, ol) : [100 x 100 x 3 x *], [100 x 100 x 3 x 1 x *] -> [1]

Validating network. 17 nodes to process in pass 2.


Validating network, final pass.


conv1_act.c: using cuDNN convolution engine for geometry: Input: 100 x 100 x 3, Output: 100 x 100 x 32, Kernel: 5 x 5 x 3, Map: 32, Stride: 1 x 1 x 3, Sharing: (1, 1, 1), AutoPad: (1, 1, 0), LowerPad: 0, UpperPad: 0.

pool1: using cuDNN convolution engine for geometry: Input: 100 x 100 x 32, Output: 49 x 49 x 32, Kernel: 3 x 3 x 1, Map: 1, Stride: 2 x 2 x 1, Sharing: (1), AutoPad: (0), LowerPad: 0, UpperPad: 0.

conv2_act.c: using cuDNN convolution engine for geometry: Input: 49 x 49 x 32, Output: 49 x 49 x 32, Kernel: 5 x 5 x 32, Map: 32, Stride: 1 x 1 x 32, Sharing: (1, 1, 1), AutoPad: (1, 1, 0), LowerPad: 0, UpperPad: 0.

pool2: using cuDNN convolution engine for geometry: Input: 49 x 49 x 32, Output: 24 x 24 x 32, Kernel: 3 x 3 x 1, Map: 1, Stride: 2 x 2 x 1, Sharing: (1), AutoPad: (0), LowerPad: 0, UpperPad: 0.

conv3_act.c: using cuDNN convolution engine for geometry: Input: 24 x 24 x 32, Output: 24 x 24 x 64, Kernel: 5 x 5 x 32, Map: 64, Stride: 1 x 1 x 32, Sharing: (1, 1, 1), AutoPad: (1, 1, 0), LowerPad: 0, UpperPad: 0.

pool3: using cuDNN convolution engine for geometry: Input: 24 x 24 x 64, Output: 11 x 11 x 64, Kernel: 3 x 3 x 1, Map: 1, Stride: 2 x 2 x 1, Sharing: (1), AutoPad: (0), LowerPad: 0, UpperPad: 0.


9 out of 27 nodes do not share the minibatch layout with the input data.

Post-processing network complete.

Loaded model with 27 nodes on GPU 0.

Training criterion node(s):
    mse = SquareError


Allocating matrices for forward and/or backward propagation.

Memory Sharing Structure:

0000000000000000: {[maskLabel Gradient[100 x 100 x 3 x *]] [rgbFeatures Gradient[100 x 100 x 3 x *]] }
000000288F28F520: {[rgbFeatures Value[100 x 100 x 3 x *]] }
000000288F296B90: {[mse Value[1]] }
000000288F2C15B0: {[h1.b Value[30000 x 1]] }
000000288F2C2C60: {[h1.W Value[30000 x 11 x 11 x 64]] }
000000288F2CAD00: {[maskLabel Value[100 x 100 x 3 x *]] }
0000002890B44E20: {[conv1_act.w Value[32 x 75]] }
0000002890B459E0: {[conv2_act.b Value[1 x 1 x 32]] }
0000002890B4A4C0: {[conv2_act.w Value[32 x 800]] }
0000002890B4C610: {[conv3_act.b Value[1 x 1 x 64]] }
0000002890B4FB00: {[conv3_act.w Value[64 x 800]] }
00000028BCA60C10: {[ol Value[100 x 100 x 3 x 1 x *]] }
00000028BCBBAFC0: {[conv3_act.b Gradient[1 x 1 x 64]] [conv3_act.out Gradient[24 x 24 x 64 x *]] [h1.t Value[30000 x *]] }
00000028BCBBB2A0: {[h1.W Gradient[30000 x 11 x 11 x 64]] [h1.z Value[30000 x 1 x *]] }
00000028BCBBB580: {[h1.t Gradient[30000 x *]] [h1.y Value[30000 x 1 x *]] }
00000028BCBBBB40: {[mse Gradient[1]] }
00000028BCBBBE20: {[h1.z Gradient[30000 x 1 x *]] [ol Gradient[100 x 100 x 3 x 1 x *]] [pool3 Gradient[11 x 11 x 64 x *]] }
00000028BCBBC100: {[h1.b Gradient[30000 x 1]] [h1.y Gradient[30000 x 1 x *]] }
00000028BCC8A4F0: {[conv1_act.out._ Value[100 x 100 x 32 x *]] [conv1_act.w Gradient[32 x 75]] }
00000028BCCFE770: {[conv1_act.c Gradient[100 x 100 x 32 x *]] [conv1_act.out Value[100 x 100 x 32 x *]] }
00000028BCCFE990: {[conv1_act.out._ Gradient[100 x 100 x 32 x *]] [pool1 Value[49 x 49 x 32 x *]] }
00000028BCD002F0: {[conv1_act.c Value[100 x 100 x 32 x *]] }
00000028BCD00530: {[conv2_act.c Value[49 x 49 x 32 x *]] }
00000028BCD00810: {[conv1_act.b Gradient[1 x 1 x 32]] [conv1_act.out Gradient[100 x 100 x 32 x *]] }
00000028BCD00AF0: {[conv2_act.out._ Value[49 x 49 x 32 x *]] [conv2_act.w Gradient[32 x 800]] }
00000028BCD00DD0: {[conv2_act.c Gradient[49 x 49 x 32 x *]] [conv2_act.out Value[49 x 49 x 32 x *]] }
00000028BCD010B0: {[conv2_act.out._ Gradient[49 x 49 x 32 x *]] [pool1 Gradient[49 x 49 x 32 x *]] [pool2 Value[24 x 24 x 32 x *]] }
00000028BCD01390: {[conv3_act.c Value[24 x 24 x 64 x *]] }
00000028BCD01670: {[conv2_act.b Gradient[1 x 1 x 32]] [conv2_act.out Gradient[49 x 49 x 32 x *]] }
00000028BCD01950: {[conv3_act.out._ Value[24 x 24 x 64 x *]] [conv3_act.w Gradient[64 x 800]] }
00000028BCD01C30: {[conv3_act.c Gradient[24 x 24 x 64 x *]] [conv3_act.out Value[24 x 24 x 64 x *]] }
00000028BCD01F10: {[conv3_act.out._ Gradient[24 x 24 x 64 x *]] [pool2 Gradient[24 x 24 x 32 x *]] [pool3 Value[11 x 11 x 64 x *]] }
00000028F10E9790: {[conv1_act.b Value[1 x 1 x 32]] }

No PreCompute nodes found, skipping PreCompute step.

LowerySJ avatar Aug 19 '16 23:08 LowerySJ

Close this issue since it's been too old. Please open a new one if needed.

cha-zhang avatar Jul 16 '17 14:07 cha-zhang