pyatc CLI Design Document
1. Background
ATC is GE offline model compilation tool, existing entry is api/atc/atc shell wrapper. This method starts ATC in new process, Python interpreter used by TBE and custom Python pass is parsed by ATC process itself, may be inconsistent with python selected by user in terminal.
This design adds ge.pyatc in ge-py distributed with CANN, uses same command line parameters as ATC, enters original ge::main_impl() main flow in current process, makes TBE/Python pass consistent with interpreter selected by user.
2. Goals and Scope
2.1 Goals
- Provide equivalent CLI entry:
python3 -m ge.pyatcand<cann_install>/bin/pyatc. - ATC parameters, help, stdout/stderr, exit code consistent with native ATC behavior; not do parameter validation in Python layer or independently maintain help text.
- Reuse
ge::main_impl()andatc_static, not add second ATC main flow. - OM/OM2/exeom product format unchanged.
2.2 Non-goals
- Not redo ATC parameter parsing and compilation logic in Python layer.
- Not promise single process multiple reentrant calls, thread safety or concurrent calls.
- Not make
main()as stable external Python API.
3. User Experience
Execute source <cann_install>/set_env.sh before using CANN environment (makes pyatc, ge package and libpyatc_wrapper.so loadable by current interpreter). Then:
pyatc <parameters same as atc>
or python3 -m ge.pyatc <parameters same as atc>
- Command line parameters passed to ATC unchanged.
pyatc --helpandatc --helpparameter content consistent, usage, examples and failure prompt entry name displayed aspyatc.python3 -m ge.pyatcis recommended writing for module entry; users can also use other Python 3 interpreters to execute-m ge.pyatcaccording to environment needs.pyatcis shell wrapper installed under<cann_install>/bin, default usespython3parsed by currentPATH, can explicitly specify interpreter throughPYTHON=/path/to/python pyatc ....
4. Overall Architecture
- Thin entry: Python side only does parameter forwarding and calling convention adaptation; ATC business logic still in
main_impland various existing modules. - CANN bin wrapper:
<cann_install>/bin/pyatconly responsible for supplementing CANNPYTHONPATH/LD_LIBRARY_PATH, and passes wrapper absolute path as originalargv[0]through Python entry function parameters; does not depend on wheelconsole_scripts, avoids binding Python interpreter when installing wheel. - Independent
libpyatc_wrapper.so: Linksatc_static, entersge::main_implthrough thin C encapsulation; separates fromlibgraph_wrapper.so,libge_runtime_wrapper.so,liboffline_compile_wrapper.so, avoids ATC global state affecting other ge-py usage.
5. Compatibility
- Original
atc/atc.binand existing ge-py API behavior unchanged. - Old version OM execution under new version not affected;
pyatcis new entry, depends on new version CANNbin/pyatcwrapper,libpyatc_wrapper.soand module code in ge-py wheel. - ge-py wheel does not declare
console_scriptsentry, avoids generating scripts that cannot be discovered byPATHor bind wrong interpreter whenpip install -t <cann_install>/python/site-packages.
6. Acceptance Criteria
pyatc --xxx,python3 -m ge.pyatc --xxxandatc --xxxoutput equivalent.pyatc --help(<cann_install>/bin/pyatcshell wrapper) behavior consistent with module entry.- Typical model compilation parameters can be transparently passed and produce OM consistent with
atc. - Process exit code consistent with ATC main flow when failing.
- TBE/custom Python pass path priority uses current process interpreter.