Upgrade your python model from paddle-1.x to paddle-2.
Attention
paddle1to2 aims to convert python files from paddle-1.x to paddle-2 one by one, it won't handle indirect imports. e.g.
# filename "a.py"
import paddle.fluid as fluid
pass
# filename "b.py"
from a import *
class MyLayer(fluid.layers.Layer):
pass
fluid.layers.Layer in "b.py" won't get converted.
So you have to make sure you have import all used paddle modules, classes, objects directly for every python file before running paddle1to2.
Install
paddle1to2 support Linux, Mac OS, Windows(Git Bash is recommended), but it requires Python 3.5.4 or higher to run. Multi-Process is supported for Linux and Mac OS, Single-Process is support for Windows, this will lead to performance difference.
- install with pip
pip install -U paddle1to2
paddle1to2 --help # show help
paddle1to2 --inpath /path/to/model.py # upgrade your model from paddle-1.x to paddle-2.0
ATTENTION: If your device contains multiple versions of python, you may need to run the following commands instead:
python3 -m pip install -U paddle1to2
python3 -m paddle1to2 -h
python3 -m paddle1to2 --inpath /path/to/model.py
- install from source
git clone https://github.com/T8T9/paddle1to2.git
cd paddle1to2
python setup.py sdist bdist_wheel
pip install -U ./dist/paddle1to2-*.whl
paddle1to2 --help # show help
paddle1to2 --inpath /path/to/model.py # upgrade your model from paddle-1.x to paddle-2.0
Develop
If you are a develop, and you want to test your code quickly, you can run the following command in project directory:
python -m paddle1to2 --inpath /path/to/model.py
#or
python paddle1to2/main.py --inpath /path/to/model.py
Moreover, if you want to run a specific refactor, you can use the following command:
python -m paddle1to2 --inpath /path/to/model.py --refactor <refactor_name>
use python -m paddle1to2 -h to see full list of all refactors.
if you want to run all unittest, use command:
python -m unittest discover paddle1to2/tests/
# or
python setup.py test
or use command:
python -m unittest paddle1to2/tests/test_refactor.py
to run specific test file.
Change Spec
change_spec is a python dict defined in spec.py, it defines the rules to refactor your code.
change_spec = {
"path.to.old_api": {
"alias": [
"path.to.old_api_alias1",
"path.to1.to2.old_api_alias2",
],
"update_to": "path.to.new_api",
"warning": "this api is deprecated.",
"args_list": ["arg1", "arg2"],
"args_change": [
["arg2", "arg2_rename"],
["arg3", ""],
["", "new_arg", "default_value"],
],
"args_warning": {"arg1":"warning message"},
"args_transformer": "_default_transformer",
},
}
alias: a list of alias of main aliaspath.to.old_api, all alias will be replaced with main alias.update_to:path.to.old_apiwill be replaced with this new api if specified.warning: print specified warning message whenpath.to.old_apiis found. This field will be ignored ifupdate_tois specified.args_list: is argument list ofpath.to.old_api.args_change: a list of list. It contains following format:["arg", "new_arg"]: rename a argument, e.g.func(arg=value)->func(new_arg=value)["arg", ""]: remove a argument, e.g.func(arg=value)->func()["", "new_arg", "default_value"]: add a new argument, e.g.func(arg=value)->func(arg=value, new_arg=default_value)
args_warning: print specified warning message for specified argument after applyargs_change.args_transformer: execute customized transformer on an AST node, it will be called after applyingargs_changeto do further refactor.
Other Tools
- find pattern of specific code snippet, usage:
find_pattern 'import paddle'
find_pattern command will traverse all nodes in AST, if you see code snippet you want, type in 'y' to get pattern.
- find match node in specific code for specific pattern, usage:
find_match_node -ss 'import paddle' -ps 'any'
you can also specify "--print-results" option to got representation of matched node, specify "--print-lineno" to got line number of matched code.
Acknowledgements
Metadata
Release files for paddle1to2 0.0.28
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| paddle1to2-0.0.28.tar.gz | 91.9 kB | Without provenance | Details for paddle1to2-0.0.28.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| paddle1to2-0.0.28-py3-none-any.whl | Python 3 | none | any | Details for paddle1to2-0.0.28-py3-none-any.whl |
Total release size: 200.0 kB
Release files / paddle1to2-0.0.28.tar.gz
| Download URL | paddle1to2-0.0.28.tar.gz |
|---|---|
| Size | 91.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea0bea34f19115c153f07a83e380ce0c2346f630cab92e0de04642edb184fbb0
|
|
BLAKE2b-256 checksum How to use checksums |
56f40b4cfbc35cfbf7b7888a4fffa4d6b4846e77072fcc153e5ae3d4df8b17bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.2
|
Release files / paddle1to2-0.0.28-py3-none-any.whl
| Download URL | paddle1to2-0.0.28-py3-none-any.whl |
|---|---|
| Size | 108.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b3ae3920619b0ebbdfede6a5295c3cfe79a983e1e056033f11f72ce434e933c
|
|
BLAKE2b-256 checksum How to use checksums |
1f82ed5c41c1a77744024f88f470380de188d9b23677dffdcae57f49e4ac2757
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.2
|
Security for paddle1to2 0.0.28
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.