You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import paddle
from copy import deepcopy
from visualdl import LogWriter
net = paddle.nn.Linear(10, 10)
with LogWriter(logdir="./log/graph_test/") as writer:
writer.add_graph(
model=net,
input_spec=[paddle.static.InputSpec([-1, 10], 'float32')],
verbose=True)
B = deepcopy(net)
Tue Mar 21 17:23:47 Dynamic-to-Static INFO: (Level -1) Not recommend to deepcopy 'Linear' decorated with @to_static, it has side effect that will rollback into original state before @to_static. Please deepcopy 'Linear' before applying @to_static.
-------------------------Graph Summary--------------------------
total operators: 4 total layers:1
-------------------- -------------------- --------------------
Name Type Count
-------------------- -------------------- --------------------
feed operator 1
matmul_v2 operator 1
elementwise_add operator 1
fetch operator 1
Linear layer 1
----------------------------------------------------------------
import paddle
from copy import deepcopy
from visualdl import LogWriter
net = paddle.nn.Linear(10, 10)
with LogWriter(logdir="./log/graph_test/") as writer:
writer.add_graph(
model=deepcopy(net), # 采用deepcopy
input_spec=[paddle.static.InputSpec([-1, 10], 'float32')],
verbose=True)
B = deepcopy(net)
-------------------------Graph Summary--------------------------
total operators: 4 total layers:1
-------------------- -------------------- --------------------
Name Type Count
-------------------- -------------------- --------------------
feed operator 1
matmul_v2 operator 1
elementwise_add operator 1
fetch operator 1
Linear layer 1
----------------------------------------------------------------
建议translate_graph使用deepcopy(model)
def translate_graph(model, input_spec, verbose=True):
model = deepcopy(model)
import paddle
with tempfile.TemporaryDirectory() as tmp:
model._full_name = '{}[{}]'.format(model.__class__.__name__, "model")
create_opname_scope(model)
model = paddle.jit.to_static(model, input_spec)
paddle.jit.save(model, os.path.join(tmp, 'temp'))
model_data = open(os.path.join(tmp, 'temp.pdmodel'), 'rb').read()
result = analyse_model(model_data)
if verbose:
print_model(result)
result = json.dumps(result, indent=2)
return result
The text was updated successfully, but these errors were encountered:
在使用
add_graph
后使用deepcopy出现Dynamic-to-Static
发现在exporter.py中translate_graph中采用
model = paddle.jit.to_static(model, input_spec)
,如果使用deepcopy(model),就不会出现警告建议
translate_graph
使用deepcopy(model)
The text was updated successfully, but these errors were encountered: