-
Notifications
You must be signed in to change notification settings - Fork 1k
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
How to deal with model checkpoint compatibility issue? #963
Comments
cc @vineelpratap @avidov @jacobkahn @xuqiantong Do we have converting scripts or any guides / hints how to do this? |
Is it impossible..?? |
It is possible =) @vineelpratap @avidov |
Hi, |
Is there any problem for providing script..?? |
yep, it is in the PR for now, need to fix some CI stuff but you can try it flashlight/flashlight#524. Please comment if you have any troubles to use it as it is in this PR. |
It is not working... I was built serialization tools from above PR, but this error message occurred. root@cd303acf12b0:~/flashlight/build/bin/asr# ./fl_asr_model_converter old {old_model_path}
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0426 06:20:01.159353 20012 ModelConverter.cpp:105] Saving params from `old binary` model to a binary dump
E0426 06:20:01.160109 95840 Serializer.h:82 Error while loading "{old_model_path}": Trying to load an unregistered polymorphic type (w2l::TransformerCriterion).
Make sure your type is registered with CEREAL_REGISTER_TYPE and that the archive you are using was included (and registered with CEREAL_REGISTER_ARCHIVE) prior to calling CEREAL_REGISTER_TYPE.
If your type is already registered and you still see this error, you may need to use CEREAL_REGISTER_DYNAMIC_INIT.
E0426 06:20:02.160425 95840 Serializer.h:82 Error while loading "{old_model_path}": Trying to load an unregistered polymorphic type (w2l::TransformerCriterion).
Make sure your type is registered with CEREAL_REGISTER_TYPE and that the archive you are using was included (and registered with CEREAL_REGISTER_ARCHIVE) prior to calling CEREAL_REGISTER_TYPE.
If your type is already registered and you still see this error, you may need to use CEREAL_REGISTER_DYNAMIC_INIT.
E0426 06:20:04.160701 95840 Serializer.h:82 Error while loading "{old_model_path}": Trying to load an unregistered polymorphic type (w2l::TransformerCriterion).
Make sure your type is registered with CEREAL_REGISTER_TYPE and that the archive you are using was included (and registered with CEREAL_REGISTER_ARCHIVE) prior to calling CEREAL_REGISTER_TYPE.
If your type is already registered and you still see this error, you may need to use CEREAL_REGISTER_DYNAMIC_INIT. I think because it also use |
Seems your old bin still doesn't have proper classes thus you cannot load model. Are you sure to use old_binary that has w2l::TransformerCriterion? Also cc @vineelpratap. |
@DongChanS - Also, can you copy the current fl::app::asr::TransformerCriterion class and create a duplicate class in the same file under namespace |
@tlikhomanenko - Yes, i'm sure. but i didn't know that the serialization tool require full AM binary (network + criterion). so i try to this with full AM binary file! Thanks! i successfully convert the wav2letter v0.2 binary to flashlight v0.3 binary But, i conducted procedures different than @vineelpratap. is it okay?
// tools/serialization/ModelConverter.cpp
std::string binaryType = argv[1];
std::string modelPath = argv[2];
std::string version;
if (binaryType == "old") {
LOG(INFO) << "Saving params from `old binary` model to a binary dump";
W2lSerializer::load(modelPath, cfg, criterion);
saveToBinaryDump(tempModelPath(modelPath).c_str(), network, criterion);
} else if (binaryType == "new") {
LOG(FATAL) << "Unsupported binary type in wav2letter";
} else {
LOG(FATAL) << "Incorrect binary type specified.";
}
root@cd303acf12b0:~/flashlight/build/bin/asr# ./fl_asr_model_converter new /root/flashlight/025_model_last.bin
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0429 07:28:43.208770 34623 ModelConverter.cpp:112] Loading model params from binary dump to `new binary` model
I0429 07:28:52.309464 34623 ModelConverter.cpp:220] Done ! But this model cannot work properly.....
|
This error message is related to Transformer module in flashlight The Flashlight v0.3's Transformer require mask unlike wav2letter v0.2's. // flashlight/flashlight/fl/contrib/modules/Transformer.cpp
std::vector<Variable> Transformer::forward(const std::vector<Variable>& input) {
// previous step[optionally], input, padMask
// padMask should be empty if previous step is provided
// padMask is expected to have "1" on the used positions and "0" on padded
// positions
if (input.size() < 2) {
throw std::invalid_argument(
"Invalid inputs for transformer block: there should be at least input and mask");
}
auto x = input.at(input.size() - 2);
if (!input.back().isempty() && x.dims(2) != input.back().dims(1)) {
throw std::invalid_argument(
"Invalid inputs for transformer block: input and Mask batch sizes are different");
} But, The Transformer encoder doesn't return mask. // flashlight/flashlight/ext/common/SequentialBuilder.cpp
fl::Variable forwardSequentialModuleWithPadMask(
const fl::Variable& input,
std::shared_ptr<fl::Module> ntwrk,
const af::array& inputSizes) {
// expected input dims T x C x 1 x B
int T = input.dims(0), B = input.dims(3);
auto inputMaxSize = af::tile(af::max(inputSizes), 1, B);
af::array inputNotPaddedSize = af::ceil(inputSizes * T / inputMaxSize);
auto padMask = af::iota(af::dim4(T, 1), af::dim4(1, B)) <
af::tile(inputNotPaddedSize, T, 1);
auto ntwrkSeq = std::dynamic_pointer_cast<fl::Sequential>(ntwrk);
auto output = input;
for (auto& module : ntwrkSeq->modules()) {
auto tr = std::dynamic_pointer_cast<fl::Transformer>(module);
auto cfr = std::dynamic_pointer_cast<fl::Conformer>(module);
if (tr != nullptr || cfr != nullptr) {
output = module->forward({output, fl::noGrad(padMask)}).front();
} else {
output = module->forward({output}).front();
}
}
return output.as(input.type());
} How to solve this problem..?? |
Sorry, I don't get what happened. So you have converted model and running decoding in fl v0.3 and see the error on the forward pass for the transformer block, right? Let me check that for s2s it should work and we have a proper call on transformer blocks everywhere. |
@DongChanS I believe you can just do
I'll let @tlikhomanenko confirm though... |
@DongChanS Please change this https://github.com/flashlight/flashlight/blob/master/flashlight/app/asr/criterion/TransformerCriterion.cpp#L284 to
I will send this fix later, but this should unblock you. Let me know if you still have problems. |
Good! Since there is some syntax error, i changed these two lines to yBatched = layer(i)->forward(std::vector<Variable>({yBatched, fl::Variable(af::array(), false)})).front(); tmp.push_back(fl::Variable(af::array(), false));
yBatched = layer(i)->forward(tmp).front(); then, the model works fine! |
Feel free to send PR on this =) |
Question
I trained Transformer (Transformer encoder + Transformer criterion) model from Wav2letter v0.2.
Unfortunately, I should use flashlight-consolidated's Wav2letter (Due to some updates in flashlight..)
But, i cannot use previous checkpoint directly.
Here is the error message.
Yes, previous checkpoint (Transformer criterion) have the type
w2l::TransformerCriterion
.It is not
fl::app::asr::TransformerCriterion
in flashlight-consolidated.How to solve this problem??
Additional Context
New version's transformer
Old version's transformer
The text was updated successfully, but these errors were encountered: