CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Model adaptation using CNTK

Open Shabnam77 opened this issue 10 years ago • 8 comments

Is there any example of model adaptation using KLD regularization?

Shabnam77 avatar Mar 18 '16 20:03 Shabnam77

Hi, I am not aware of such model, but I will add it as a documentation request. If we have any handy, I will share them with you next week; if not, we will develop one.

mradmila avatar Mar 20 '16 21:03 mradmila

Thanks for your rely. Based on the current CNTK documentation I have the following config. file for model adaptation:

TIMIT_adapt=[ action=adapt

modelPath=./TrainSimpleNetwork/adapted/cntkSpeech.dnn
originalModelFileName=./TrainSimpleNetwork/model/cntkSpeech.dnn
refNodeName=HLast

adaptationRegType=KL
adaptationRegWeight=0.75

........ ]

This config file gives me the following error. Do you have any idea what might be wrong here?

minibatchframesourcemulti: read label set 0: 1960 classes

minibatchframesourcemulti: feature set 0: 84488 frames read from 404 utterances minibatchframesourcemulti: 48 files out of 404 not found in label set biggrowablevectorarray: disk backup store created, 84488 frames, 8388608 bytes Load Network From the original model file .

[CALL STACK] ./CNTK-master/build/release/lib/libcntkmath.so ( Microsoft::MSR::CNTK::ExceptionWithCallStackstd::runtime_error::CollectCallStack(std::function<void (std::string)> const&, std::function<void ()> const&) + 0x101 ) [0x7effdcc305a1] ./CNTK-master/build/release/lib/libcntkmath.so ( Microsoft::MSR::CNTK::ExceptionWithCallStackstd::runtime_error::PrintCallStack() + 0x88 ) [0x7effdcc30a38] cntk ( void Microsoft::MSR::CNTK::ThrowFormattedstd::runtime_error(char const_, ...) + 0xe2 ) [0x541162] ./CNTK-master/build/release/lib/libcntkmath.so ( Microsoft::MSR::CNTK::File::Init(wchar_t const_, int) + 0x600 ) [0x7effdcc34210] ./CNTK-master/build/release/lib/libcntkmath.so ( Microsoft::MSR::CNTK::File::File(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, int) + 0x1f ) [0x7effdcc3456f] cntk ( void Microsoft::MSR::CNTK::ComputationNetwork::Read(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) + 0x40 ) [0x6a3570] cntk ( std::shared_ptrMicrosoft::MSR::CNTK::ComputationNetwork Microsoft::MSR::CNTK::ComputationNetwork::CreateFromFile(int, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) + 0x2e3 ) [0x711123] cntk ( Microsoft::MSR::CNTK::SGD::Adapt(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, Microsoft::MSR::CNTK::IDataReader, Microsoft::MSR::CNTK::IDataReader, int, bool) + 0x5d6 ) [0x72cf76] cntk ( void DoAdapt(Microsoft::MSR::CNTK::ConfigParameters const&) + 0x44b ) [0x74239b] cntk ( void DoCommands(Microsoft::MSR::CNTK::ConfigParameters const&) + 0xb2c ) [0x596ecc] cntk ( wmainOldCNTKConfig(int, wchar_t**) + 0x909 ) [0x53aab9] cntk ( wmain1(int, wchar_t**) + 0x70 ) [0x53b110] cntk ( main + 0xd8 ) [0x52fd78] /lib/x86_64-linux-gnu/libc.so.6 ( __libc_start_main + 0xed ) [0x7effdb89376d] cntk ( ) [0x533b45] EXCEPTION occurred: File: filename is empty

Shabnam77 avatar Mar 23 '16 19:03 Shabnam77

It is called origModelFileName.

wstring origModelFileName = config(L"origModelFileName", L"");

mradmila avatar Mar 23 '16 21:03 mradmila

Thank you. It would be great if you edit the adapt command section at https://github.com/Microsoft/CNTK/wiki/Top-level%20commands

Shabnam77 avatar Mar 23 '16 22:03 Shabnam77

After changing the orignalModelFileName to origModelFileName, I see the following error! It looks like CNTK does not see the mini-batch size from the original model and assumes it is 0!! 512 is the mini-batch size in the original model and also in the adapt config. file.

... recoverblock: recovering feature block 14 [917504..983039) recoverblock: recovering feature block 15 [983040..1048575) recoverblock: recovering feature block 16 [1048576..1114111) recoverblock: recovering feature block 17 [1114112..1179647)

Starting minibatch loop.

[CALL STACK] /home/sxg121431/CNTK-master/build/release/lib/libcntkmath.so ( Microsoft::MSR::CNTK::ExceptionWithCallStackstd::logic_error::CollectCallStack(std::function<void (std::string)> const&, std::function<void ()> const&) + 0x101 ) [0x7f425b13ce01] /home/sxg121431/CNTK-master/build/release/lib/libcntkmath.so ( Microsoft::MSR::CNTK::ExceptionWithCallStackstd::logic_error::PrintCallStack() + 0x88 ) [0x7f425b13d298] cntk ( void Microsoft::MSR::CNTK::ThrowFormattedstd::logic_error(char const_, ...) + 0xe2 ) [0x5439b2] cntk ( Microsoft::MSR::CNTK::ComputationNode::NotifyFunctionValuesMBSizeModified() + 0x496 ) [0x544a06] cntk ( bool Microsoft::MSR::CNTK::DataReaderHelpers::GetMinibatchIntoNetwork(Microsoft::MSR::CNTK::IDataReader&, std::shared_ptrMicrosoft::MSR::CNTK::ComputationNetwork, std::shared_ptrMicrosoft::MSR::CNTK::ComputationNodeBase, bool, bool, std::map<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, Microsoft::MSR::CNTK::Matrix, std::less<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > >, std::allocator<std::pair<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const, Microsoft::MSR::CNTK::Matrix> > >&, unsigned long&) + 0x1f7 ) [0x71f777] cntk ( Microsoft::MSR::CNTK::SGD::TrainOneEpoch(std::shared_ptrMicrosoft::MSR::CNTK::ComputationNetwork, std::shared_ptrMicrosoft::MSR::CNTK::ComputationNetwork, std::shared_ptrMicrosoft::MSR::CNTK::ComputationNodeBase const&, int, unsigned long, Microsoft::MSR::CNTK::IDataReader, double, unsigned long, std::vectorstd::shared_ptr<Microsoft::MSR::CNTK::ComputationNodeBase, std::allocatorstd::shared_ptr<Microsoft::MSR::CNTK::ComputationNodeBase > > const&, std::vectorstd::shared_ptr<Microsoft::MSR::CNTK::ComputationNodeBase, std::allocatorstd::shared_ptr<Microsoft::MSR::CNTK::ComputationNodeBase > > const&, std::vectorstd::shared_ptr<Microsoft::MSR::CNTK::ComputationNodeBase, std::allocatorstd::shared_ptr<Microsoft::MSR::CNTK::ComputationNodeBase > > const&, std::vectorstd::shared_ptr<Microsoft::MSR::CNTK::ComputationNodeBase, std::allocatorstd::shared_ptr<Microsoft::MSR::CNTK::ComputationNodeBase > > const&, std::map<std::basic_string<wchar_t, s cntk ( Microsoft::MSR::CNTK::SGD::TrainOrAdaptModel(int, std::shared_ptrMicrosoft::MSR::CNTK::ComputationNetwork, bool, std::shared_ptrMicrosoft::MSR::CNTK::ComputationNetwork, std::shared_ptrMicrosoft::MSR::CNTK::ComputationNodeBase, Microsoft::MSR::CNTK::IDataReader, Microsoft::MSR::CNTK::IDataReader) + 0x1218) [0x72a908] cntk ( Microsoft::MSR::CNTK::SGD::Adapt(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, Microsoft::MSR::CNTK::IDataReader, Microsoft::MSR::CNTK::IDataReader_, int, bool) + 0x43d ) [0x72cddd] cntk ( void DoAdapt(Microsoft::MSR::CNTK::ConfigParameters const&) + 0x44b ) [0x74239b] cntk ( void DoCommands(Microsoft::MSR::CNTK::ConfigParameters const&) + 0xb2c ) [0x596ecc] cntk ( wmainOldCNTKConfig(int, wchar_t**) + 0x909 ) [0x53aab9] cntk ( wmain1(int, wchar_t**) + 0x70 ) [0x53b110] cntk ( main + 0xd8 ) [0x52fd78] /lib/x86_64-linux-gnu/libc.so.6 ( __libc_start_main + 0xed ) [0x7f4259d9f76d] cntk ( ) [0x533b45] EXCEPTION occurred: NotifyFunctionValuesMBSizeModified: features InputValue operation had its col dimension 0 changed by the reader to 512, but different from MBLayout.

Shabnam77 avatar Mar 23 '16 23:03 Shabnam77

Looks like I am to blame. Adaptation has become the victim of a refactoring. It is possible that this feature is currently not functional. My apologies.

If you are compiling from sources, then a workaround may be the following modification in Source/SGDLib/SGD.cpp, but I have not been able to test this other than it passes compilation, my apologies again. If you try it, would you please let me know whether that solved it or not:

        const_cast<MBLayoutPtr&>(refNet->GetMBLayoutPtr()) = net->GetMBLayoutPtr(); // <--- add this line
        refNet->CompileNetwork();   // <-- search for this line to find the location

frankseide avatar Mar 24 '16 23:03 frankseide

I add this line to SGD.cpp. Then the problem reported by Shabnam77 is solved, but after starting minitatch loop, another error occurred.

Starting minibatch loop. getbatch: getting utterances 65..65 (1116 subset of 1116 frames out of 64 requested) in sweep 0 getbatch: getting utterances 66..66 (892 subset of 892 frames out of 64 requested) in sweep 0 getbatch: getting utterances 67..67 (685 subset of 685 frames out of 64 requested) in sweep 0 getbatch: getting utterances 68..68 (948 subset of 948 frames out of 64 requested) in sweep 0 getbatch: getting utterances 69..69 (1714 subset of 1714 frames out of 64 requested) in sweep 0 getbatch: getting utterances 70..70 (767 subset of 767 frames out of 64 requested) in sweep 0 getbatch: getting utterances 71..71 (1205 subset of 1205 frames out of 64 requested) in sweep 0 getbatch: getting utterances 72..72 (1028 subset of 1028 frames out of 64 requested) in sweep 0 getbatch: getting utterances 73..73 (966 subset of 966 frames out of 64 requested) in sweep 0 getbatch: getting utterances 74..74 (836 subset of 836 frames out of 64 requested) in sweep 0 getbatch: getting utterances 75..75 (901 subset of 901 frames out of 64 requested) in sweep 0 Segmentation fault (core dumped)

minghuaiping avatar Jul 28 '16 01:07 minghuaiping

Closing this one, please try with the latest bits. Thanks.

pkranen avatar Jul 07 '17 09:07 pkranen