MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / dump

Method dump

imperative/python/megengine/utils/network.py:165–268  ·  view source on GitHub ↗

r"""Serializes graph to file. Args: file: output file, could be file object or filename. append: whether output is appended to ``file``. Only works when ``file`` is str. keep_var_name: level for keeping variable names: * 0

(
        self,
        file,
        *,
        keep_var_name: int = 1,
        keep_opr_name: bool = False,
        keep_param_name: bool = False,
        keep_opr_priority: bool = False,
        strip_info_file=None,
        append_json=False,
        optimize_for_inference=True,
        append=False,
        user_info: Any = None,
        enable_metadata=True,
        dump_format: str = None,
        compat_older_version: str = None,
        **kwargs
    )

Source from the content-addressed store, hash-verified

163 return list(self._get_var(var) for var in new_vars)
164
165 def dump(
166 self,
167 file,
168 *,
169 keep_var_name: int = 1,
170 keep_opr_name: bool = False,
171 keep_param_name: bool = False,
172 keep_opr_priority: bool = False,
173 strip_info_file=None,
174 append_json=False,
175 optimize_for_inference=True,
176 append=False,
177 user_info: Any = None,
178 enable_metadata=True,
179 dump_format: str = None,
180 compat_older_version: str = None,
181 **kwargs
182 ):
183 r"""Serializes graph to file.
184
185 Args:
186 file: output file, could be file object or filename.
187 append: whether output is appended to ``file``.
188 Only works when ``file`` is str.
189 keep_var_name: level for keeping variable names:
190
191 * 0: none of the names are kept
192 * 1: (default)keep names of output vars
193 * 2: keep names of all (output and internal) vars
194
195 keep_opr_name: whether to keep operator names.
196 keep_param_name: whether to keep param names, so param values can be
197 easily manipulated after loading model
198 keep_opr_priority: whether to keep priority setting for operators
199 strip_info_file: a string for path or a file handler. if is not None,
200 then the dump information for code strip would be written to ``strip_info_file``
201 append_json: will be check when `strip_info_file` is not None. if set
202 true, the information for code strip will be append to strip_info_file.
203 if set false, will rewrite strip_info_file
204 optimize_for_inference: enbale optmizations,
205 will skip all optimize options if this is False. Default: True
206 user_info: any type object, which will be pickled to bytes.
207 enable_metadata: whether to save metadata into output file.
208 dump_format: using different dump formats. the open source MegEngine
209 defaults to the FBS_V2 format, there are two format FBS_V2 and FBS to choose,
210 internal MegEngine have an other choice of internal proprietary formats
211 compat_older_version: the specified megbrain version which is less than 8.16 for model forward compatibility, only support "8.14" currently. Default: None.
212
213 See more detials in :meth:`~.trace.dump`.
214 """
215 if compat_older_version:
216 compat_older_version = compat_older_version.strip()
217 assert (
218 compat_older_version == "8.14"
219 ), "Forward compatibility for older version only support 8.14 currently."
220 assert (
221 dump_format == "FBS"
222 ), "forward compatibility for older version only works when dump_format is FBS"

Callers

nothing calls this directly

Calls 4

_compileMethod · 0.95
listFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected