diff --git a/docs/en/faq_en.md b/docs/en/faq_en.md index e006870bfaacef21bbadc6aaade496557c52180f..6f34117fd46ac4db24c4c369e41a3e11ce835a9a 100644 --- a/docs/en/faq_en.md +++ b/docs/en/faq_en.md @@ -45,7 +45,15 @@ VALID: >> * Q: What should I do if I want to transform the weights' format from `pdparams` to an earlier version(before Paddle1.7.0), which consists of the scattered files? -* A: You can use `fluid.load` to load the `pdparams` weights and use `fluid.io.save_vars` to save the weights as scattered files. +* A: You can use `fluid.load` to load the `pdparams` weights and use `fluid.io.save_vars` to save the weights as scattered files. The demo is as follows. Finally all the scattered files will be saved in the path `path_to_save_var`. +``` +fluid.load( + program=infer_prog, model_path=args.pretrained_model, executor=exe) +state = fluid.io.load_program_state(args.pretrained_model) +def exists(var): + return var.name in state +fluid.io.save_vars(exe, "./path_to_save_var", infer_prog, predicate=exists) +``` >> diff --git a/docs/zh_CN/faq.md b/docs/zh_CN/faq.md index dd73b674a113c93a444f76134ccaf20cda0e9db8..bd5401475e9be71a91adc3738dd27ff6a42d4191 100644 --- a/docs/zh_CN/faq.md +++ b/docs/zh_CN/faq.md @@ -45,7 +45,15 @@ VALID: >> * Q: 如果想将保存的`pdparams`模型参数文件转换为早期版本(Paddle1.7.0之前)的零碎文件(每个文件均为一个单独的模型参数),该怎么实现呢? -* A: 可以首先导入`pdparams`模型,之后使用`fluid.io.save_vars`函数将模型保存为零散的碎文件。 +* A: 可以首先导入`pdparams`模型,之后使用`fluid.io.save_vars`函数将模型保存为零散的碎文件。示例代码如下,最终所有零散文件会被保存在`path_to_save_var`目录下。 +``` +fluid.load( + program=infer_prog, model_path=args.pretrained_model, executor=exe) +state = fluid.io.load_program_state(args.pretrained_model) +def exists(var): + return var.name in state +fluid.io.save_vars(exe, "./path_to_save_var", infer_prog, predicate=exists) +``` >>