Skip to content

Commit bd84409

Browse files
committed
move save/load from nn.py to tensor.py
1 parent 1b28739 commit bd84409

File tree

2 files changed

+72
-72
lines changed

2 files changed

+72
-72
lines changed

python/paddle/fluid/layers/nn.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,75 +3265,3 @@ def autoincreased_step_counter(counter_name=None, begin=1, step=1):
32653265
counter.stop_gradient = True
32663266

32673267
return counter
3268-
3269-
3270-
def save(x, file_path, overwrite=True):
3271-
"""
3272-
Saves a variable as a file.
3273-
3274-
Args:
3275-
x(variable): The Tensor/LoDTensor to be saved.
3276-
file_path(str): The file path where the variable will be saved.
3277-
overwrite(bool): Whether or not cover the given file when it has already
3278-
existed. If it's set 'False' and the file is existed, a runtime
3279-
error will be thrown.
3280-
"""
3281-
helper = LayerHelper("save", **locals())
3282-
helper.append_op(
3283-
type="save",
3284-
inputs={"input": x},
3285-
outputs={},
3286-
args={"file_path": file_path,
3287-
"overwrite": overwrite})
3288-
3289-
3290-
def save_combine(x, file_path, overwrite=True):
3291-
"""
3292-
Saves a list of variables into a single file.
3293-
3294-
Args:
3295-
x(list): A list of Tensor/LoDTensor to be saved together in a single file.
3296-
file_path(str): The file path where variables will be saved.
3297-
overwrite(bool): Whether or not cover the given file when it has already
3298-
existed. If it's set 'False' and the file is existed, a runtime
3299-
error will be thrown.
3300-
"""
3301-
helper = LayerHelper("save_combine", **locals())
3302-
helper.append_op(
3303-
type="save_combine",
3304-
inputs={"input": x},
3305-
outputs={},
3306-
args={"file_path": file_path,
3307-
"overwrite": overwrite})
3308-
3309-
3310-
def load(out, file_path):
3311-
"""
3312-
Loads a variable from a given file.
3313-
3314-
Args:
3315-
out(variable): The variable to be read from the disk file.
3316-
file_path(str): The path of the disk file.
3317-
"""
3318-
helper = LayerHelper("load", **locals())
3319-
helper.append_op(
3320-
type="load",
3321-
inputs={},
3322-
output={"Out": out},
3323-
args={"file_path": file_path})
3324-
3325-
3326-
def load_combine(out, file_path):
3327-
"""
3328-
Loads a list of vairables from a single file.
3329-
3330-
Args:
3331-
out(list): The list of variables to be read from the disk file.
3332-
file_path(str): The path of the disk file.
3333-
"""
3334-
helper = LayerHelper("load_combine", **locals())
3335-
helper.append_op(
3336-
type="load_combine",
3337-
inputs={},
3338-
output={"Out": out},
3339-
args={"file_path": file_path})

python/paddle/fluid/layers/tensor.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,75 @@ def zeros(shape, dtype, force_cpu=False):
362362
data = fluid.layers.zeros(shape=[1], dtype='int64')
363363
"""
364364
return fill_constant(value=0.0, **locals())
365+
366+
367+
def save(x, file_path, overwrite=True):
368+
"""
369+
Saves a variable as a file.
370+
371+
Args:
372+
x(variable): The Tensor/LoDTensor to be saved.
373+
file_path(str): The file path where the variable will be saved.
374+
overwrite(bool): Whether or not cover the given file when it has already
375+
existed. If it's set 'False' and the file is existed, a runtime
376+
error will be thrown.
377+
"""
378+
helper = LayerHelper("save", **locals())
379+
helper.append_op(
380+
type="save",
381+
inputs={"input": x},
382+
outputs={},
383+
args={"file_path": file_path,
384+
"overwrite": overwrite})
385+
386+
387+
def save_combine(x, file_path, overwrite=True):
388+
"""
389+
Saves a list of variables into a single file.
390+
391+
Args:
392+
x(list): A list of Tensor/LoDTensor to be saved together in a single file.
393+
file_path(str): The file path where variables will be saved.
394+
overwrite(bool): Whether or not cover the given file when it has already
395+
existed. If it's set 'False' and the file is existed, a runtime
396+
error will be thrown.
397+
"""
398+
helper = LayerHelper("save_combine", **locals())
399+
helper.append_op(
400+
type="save_combine",
401+
inputs={"input": x},
402+
outputs={},
403+
args={"file_path": file_path,
404+
"overwrite": overwrite})
405+
406+
407+
def load(out, file_path):
408+
"""
409+
Loads a variable from a given file.
410+
411+
Args:
412+
out(variable): The variable to be read from the disk file.
413+
file_path(str): The path of the disk file.
414+
"""
415+
helper = LayerHelper("load", **locals())
416+
helper.append_op(
417+
type="load",
418+
inputs={},
419+
output={"Out": out},
420+
args={"file_path": file_path})
421+
422+
423+
def load_combine(out, file_path):
424+
"""
425+
Loads a list of vairables from a single file.
426+
427+
Args:
428+
out(list): The list of variables to be read from the disk file.
429+
file_path(str): The path of the disk file.
430+
"""
431+
helper = LayerHelper("load_combine", **locals())
432+
helper.append_op(
433+
type="load_combine",
434+
inputs={},
435+
output={"Out": out},
436+
args={"file_path": file_path})

0 commit comments

Comments
 (0)