Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

多GPU模型使用exe.run得到的损失是一个GPU个数的numpy

Open guozhiyao opened this issue 7 years ago • 1 comments

为使您的问题得到快速解决,在建立Issues前,请您先通过如下方式搜索是否有相似问题:【搜索issue关键字】【使用labels筛选】【官方文档】

如果您没有查询到相似问题,为快速解决您的提问,建立issue时请提供如下细节信息:

  • 标题:简洁、精准概括您的问题,例如“Insufficient Memory xxx" ”
  • 版本、环境信息:    1)PaddlePaddle版本:1.5.1    2)CPU:无    3)GPU:4张Tesla P4,CUDA 9.0,CUDNN 7.2    4)系统环境:CentOS,python3.6
  • 训练信息    1)单机多卡

代码: `import paddle.fluid as fluid import numpy import os

use_cuda = True place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()

if not use_cuda: os.environ['CPU_NUM'] = str(2)

exe = fluid.Executor(place)

train_program = fluid.Program() startup_program = fluid.Program() with fluid.program_guard(train_program, startup_program): data = fluid.layers.data(name='X', shape=[1], dtype='float32') hidden = fluid.layers.fc(input=data, size=10) loss = fluid.layers.mean(hidden) test_program = fluid.default_main_program().clone(for_test=True) fluid.optimizer.SGD(learning_rate=0.01).minimize(loss)

startup_program.random_seed=1 exe.run(startup_program)

train_exe = fluid.ParallelExecutor(use_cuda=use_cuda, main_program=train_program, loss_name=loss.name) test_exe = fluid.ParallelExecutor(use_cuda=use_cuda, main_program=test_program, share_vars_from=train_exe)

x = numpy.random.random(size=(10, 1)).astype('float32') loss_data, = train_exe.run(feed={"X": x}, fetch_list=[loss.name])

loss_data, = test_exe.run(feed={"X": x}, fetch_list=[loss.name]) print(loss_data)`

输出: W0819 21:01:42.367696 11604 device_context.cc:259] Please NOTE: device: 0, CUDA Capability: 61, Driver API Version: 9.2, Runtime API Version: 9.0 W0819 21:01:42.370872 11604 device_context.cc:267] device: 0, cuDNN Version: 7.2. W0819 21:01:42.370890 11604 device_context.cc:293] WARNING: device: 0. The installed Paddle is compiled with CUDNN 7.3, but CUDNN version in your machine is 7.2, which may cause serious incompatible bug. Please recompile or reinstall Paddle with compatible CUDNN version. WARNING:root: You can try our memory optimize feature to save your memory usage: # create a build_strategy variable to set memory optimize option build_strategy = compiler.BuildStrategy() build_strategy.enable_inplace = True build_strategy.memory_optimize = True

     # pass the build_strategy to with_data_parallel API
     compiled_prog = compiler.CompiledProgram(main).with_data_parallel(
         loss_name=loss.name, build_strategy=build_strategy)

 !!! Memory optimize is our experimental feature !!!
     some variables may be removed/reused internal to save memory usage,
     in order to fetch the right value of the fetch_list, please set the
     persistable property to true for each variable in fetch_list

     # Sample
     conv1 = fluid.layers.conv2d(data, 4, 5, 1, act=None)
     # if you need to fetch conv1, then:
     conv1.persistable = True

I0819 21:01:44.300786 11604 parallel_executor.cc:329] The number of CUDAPlace, which is used in ParallelExecutor, is 4. And the Program will be copied 4 copies I0819 21:01:45.407585 11604 build_strategy.cc:340] SeqOnlyAllReduceOps:0, num_trainers:1 WARNING:root: You can try our memory optimize feature to save your memory usage: # create a build_strategy variable to set memory optimize option build_strategy = compiler.BuildStrategy() build_strategy.enable_inplace = True build_strategy.memory_optimize = True

     # pass the build_strategy to with_data_parallel API
     compiled_prog = compiler.CompiledProgram(main).with_data_parallel(
         loss_name=loss.name, build_strategy=build_strategy)

 !!! Memory optimize is our experimental feature !!!
     some variables may be removed/reused internal to save memory usage,
     in order to fetch the right value of the fetch_list, please set the
     persistable property to true for each variable in fetch_list

     # Sample
     conv1 = fluid.layers.conv2d(data, 4, 5, 1, act=None)
     # if you need to fetch conv1, then:
     conv1.persistable = True

share_vars_from is set, scope is ignored. I0819 21:01:45.409354 11604 parallel_executor.cc:329] The number of CUDAPlace, which is used in ParallelExecutor, is 4. And the Program will be copied 4 copies I0819 21:01:45.409639 11604 build_strategy.cc:340] SeqOnlyAllReduceOps:0, num_trainers:1 [0.09861097 0.26964137 0.20171605 0.26357183]

Thank you for contributing to PaddlePaddle. Before submitting the issue, you could search issue in the github in case that there was a similar issue submitted or resolved before. If there is no solution,please make sure that this is a training issue including the following details: System information -PaddlePaddle version (eg.1.1)or CommitID -CPU: including CPUMKL/OpenBlas/MKLDNN version -GPU: including CUDA/CUDNN version -OS Platform (eg.Mac OS 10.14) -Other imformation: Distriuted training/informantion of operator/ Graphics card storage To Reproduce Steps to reproduce the behavior Describe your current behavior Code to reproduce the issue Other info / logs

guozhiyao avatar Aug 19 '19 13:08 guozhiyao

对于多卡的losses data,你可以做mean操作(numpy.mean)

liupluswei avatar Aug 19 '19 14:08 liupluswei