@@ -35,7 +35,7 @@ def save_vars(executor, dirname, main_program=None, vars=None, predicate=None):
35
35
36
36
:param executor: executor that save variable
37
37
:param dirname: directory path
38
- :param main_program: program. If vars is None, then filter all variables in this
38
+ :param main_program: program. If vars is None, then filter all variables in this
39
39
program which fit `predicate`. Default g_program.
40
40
:param predicate: The Predicate describes a callable that returns a variable
41
41
as a bool. If it returns true, the variables will be saved.
@@ -96,11 +96,11 @@ def load_vars(executor, dirname, main_program=None, vars=None, predicate=None):
96
96
97
97
:param executor: executor that save variable
98
98
:param dirname: directory path
99
- :param main_program: program. If vars is None, then filter all variables in this
99
+ :param main_program: program. If vars is None, then filter all variables in this
100
100
program which fit `predicate`. Default g_program.
101
101
:param predicate: The Predicate describes a callable that returns a variable
102
102
as a bool. If it returns true, the variables will be loaded.
103
- :param vars: variables need to be loaded. If specify vars, program &
103
+ :param vars: variables need to be loaded. If specify vars, program &
104
104
predicate will be ignored
105
105
:return: None
106
106
"""
@@ -157,15 +157,15 @@ def save_inference_model(dirname,
157
157
executor ,
158
158
main_program = None ):
159
159
"""
160
- Build a model especially for inference,
160
+ Build a model especially for inference,
161
161
and save it to directory by the executor.
162
162
163
163
:param dirname: directory path
164
164
:param feeded_var_names: Names of variables that need to be feeded data during inference
165
165
:param target_vars: Variables from which we can get inference results.
166
166
:param executor: executor that save inference model
167
- :param main_program: original program, which will be pruned to build the inference model.
168
- Default g_program .
167
+ :param main_program: original program, which will be pruned to build the inference model.
168
+ Default g_main_program .
169
169
170
170
:return: None
171
171
"""
@@ -234,3 +234,35 @@ def load_inference_model(dirname, executor):
234
234
fetch_vars = [program .global_block ().var (name ) for name in fetch_var_names ]
235
235
236
236
return [program , feed_var_names , fetch_vars ]
237
+
238
+
239
+ def get_parameter_value (para , executor ):
240
+ """
241
+ Get the LoDTensor for the parameter
242
+
243
+ :param executor: executor for retrieving the value
244
+ :param para: the given parameter
245
+ :return: the LoDTensor for the parameter
246
+ """
247
+ assert is_parameter (para )
248
+
249
+ get_program = Program ()
250
+ block = get_program .global_block ()
251
+ new_var = _clone_var_in_block_ (block , para )
252
+ return executor .run (get_program , feed = {}, fetch_list = [new_var ])[0 ]
253
+
254
+
255
+ def get_parameter_value_by_name (name , executor , program = None ):
256
+ """
257
+ Get the LoDTensor for paramter with the given name
258
+
259
+ :param executor: executor for retrieving the value
260
+ :param name: the name of the parameter
261
+ :param program: the program where the variable is found
262
+ Default g_main_program.
263
+ :return: the LoDTensor for the variable
264
+ """
265
+ if program is None :
266
+ program = g_main_program
267
+ var = program .global_block ().var (name )
268
+ return get_parameter_value (var , executor )
0 commit comments