Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Very Large CPU RAM Memory Consumption (>1GB) #15148

Open
rvardimon opened this issue Jun 4, 2019 · 7 comments
Open

Very Large CPU RAM Memory Consumption (>1GB) #15148

rvardimon opened this issue Jun 4, 2019 · 7 comments

Comments

@rvardimon
Copy link

rvardimon commented Jun 4, 2019

Description

Mxnet consumes nearly 2GB CPU RAM even when loading a relatively small model (e.g. Resnet-18) directed on GPU (ctx=mxnet.gpu()). From what I understand, there is no real need to use so much CPU memory when the model is running on GPU.

This issue is extremely prohibitive when trying to run multiple processes with mxnet on the same machine, and IMO gives it a significant disadvantage compared to other frameworks for being used in AI production systems.

Environment info

/usr/bin/python3.6 /home/ran-face/src/CameraResearch/workspace/mxnet_diagnose.py
----------Python Info----------
Version      : 3.6.7
Compiler     : GCC 8.2.0
Build        : ('default', 'Oct 22 2018 11:32:17')
Arch         : ('64bit', 'ELF')
------------Pip Info-----------
Version      : 9.0.1
Directory    : /usr/lib/python3/dist-packages/pip
----------MXNet Info-----------
Version      : 1.3.1
Directory    : /usr/local/lib/python3.6/dist-packages/mxnet
Commit Hash   : 19c501680183237d52a862e6ae1dc4ddc296305b
----------System Info----------
Platform     : Linux-4.15.0-45-generic-x86_64-with-Ubuntu-18.04-bionic
system       : Linux
node         : ranface-Lenovo-Y720-15IKB
release      : 4.15.0-45-generic
version      : #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019
----------Hardware Info----------
machine      : x86_64
processor    : x86_64
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              8
On-line CPU(s) list: 0-7
Thread(s) per core:  2
Core(s) per socket:  4
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               158
Model name:          Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Stepping:            9
CPU MHz:             2411.711
CPU max MHz:         3800.0000
CPU min MHz:         800.0000
BogoMIPS:            5616.00
Virtualization:      VT-x
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            6144K
NUMA node0 CPU(s):   0-7
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp flush_l1d
----------Network Test----------
Setting timeout: 10
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0694 sec, LOAD: 0.9665 sec.
Timing for Gluon Tutorial(en): http://gluon.mxnet.io, DNS: 0.0841 sec, LOAD: 1.2019 sec.
Timing for Gluon Tutorial(cn): https://zh.gluon.ai, DNS: 0.0988 sec, LOAD: 0.9435 sec.
Timing for FashionMNIST: https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0708 sec, LOAD: 1.2242 sec.
Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0637 sec, LOAD: 1.3118 sec.
Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 0.0499 sec, LOAD: 0.3116 sec.

Process finished with exit code 0

Package used (Python/R/Scala/Julia):
I'm using Python3

Build info

mxnet installed using pip3

Steps to reproduce

(Paste the commands you ran that produced the error.)

  1. Run the following code
import mxnet as mx
import time

if __name__ == '__main__':

    path='http://data.mxnet.io/models/imagenet/'
    [mx.test_utils.download(path+'resnet/18-layers/resnet-18-0000.params'),
     mx.test_utils.download(path+'resnet/18-layers/resnet-18-symbol.json'),
     mx.test_utils.download(path+'synset.txt')]

    ctx = mx.gpu()

    sym, arg_params, aux_params = mx.model.load_checkpoint('resnet-18', 0)
    mod = mx.mod.Module(symbol=sym, context=ctx, label_names=None)
    mod.bind(for_training=False, data_shapes=[('data', (1,3,224,224))],
             label_shapes=mod._label_shapes)
    mod.set_params(arg_params, aux_params, allow_missing=True)

    time.sleep(100)
  1. check process memory (run top, shift M to sort processes by memory usage)
  2. memory usage is about ~1.5-2GB RAM
@mxnet-label-bot
Copy link
Contributor

Hey, this is the MXNet Label Bot.
Thank you for submitting the issue! I will try and suggest some labels so that the appropriate MXNet community members can help resolve it.
Here are my recommended labels: Performance

@ddavydenko
Copy link
Contributor

@mxnet-label-bot Add [Performance, Memory]

@anirudh2290
Copy link
Member

@rvardimon thanks for raising the issue. Have you looked at the profiler output from mxnet , when you load the model params it initially loads on cpu so you may see a spike but then it should be released after set_params is called. if not module api is adding some overhead which should be looked at: @karan6181

@karan6181
Copy link
Contributor

  • I see roughly 2 GB of CPU memory usage when I ran the user script and also with the below minimum reproducible script using Gluon.

  • import mxnet as mx
    import gluoncv
    from time import sleep
    
    net = gluoncv.model_zoo.get_model('cifar_resnet20_v1', pretrained=True, ctx=mx.gpu())
    net.hybridize()
    
    #print(net.summary(mx.nd.ones((1, 3,28,28), ctx=mx.gpu())))
    sleep(20)
  • I tried using different MXNet version but the CPU memory usage keeps on increasing. Not Much difference in memory consumption if using with/without MKL.

  • # P3.16xLarge
    # DLAMI V24
    
    MXNet-cu92: 1.3.1: 2.15 GB
    MXNet-cu92: 1.4.1: 2.3 GB
    MXNet-cu92: 1.5.0: 2.55 GB
    MXNet-cu92: 1.6.0(1.6.0b20190906): 2.9 GB 
  • If I run the same above script on CPU context, then the memory usage is approx. 100 MB.

@anirudh2290
Copy link
Member

We ( I and @karan6181 ) looked at a bunch of things to understand where the overhead is coming from. We looked at Resource Request and attach op resources pass. We looked at object pool in threaded engine, and at turning off OPENMP and MKLDNN and checking, but the overhead is still there. We looked at the overhead caused by different arrays in the module api. Overhead is not coming from any of these areas.

We also check that increase in memory consumption happens at the bind stage and probably coming from somewhere in the graph executor. Next step is to check this in 1.2.1 to see if the increase happened in 1.3.1.

@jiangwch
Copy link

19   1488.9 MiB    252.7 MiB           sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch)
20   1489.0 MiB      0.1 MiB           all_layers = sym.get_internals()
21   1489.1 MiB      0.1 MiB           sym = all_layers['fc1_output']
22   1489.2 MiB      0.1 MiB           self.model = mx.mod.Module(symbol=sym, context=ctx, label_names=None)
23   3331.3 MiB   1842.2 MiB           self.model.bind(data_shapes=[('data', (1, 3, 112, 112))])
24   3333.9 MiB      2.5 MiB           self.model.set_params(arg_params, aux_params)

I used mxnet-cu100mkl 1.4.1 in win10.

@MyraBaba
Copy link

MyraBaba commented Apr 8, 2022

@anirudh2290 Hi did you discover any solution for this memory consumption issue ?

Best

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants