'How To Limit Python Memory Usage?

Currently i'm working at Python Project, and i have a 2.12 GB model which has to be processed.

This is the code :

model = PegasusForConditionalGeneration.from_pretrained("google/pegasus-xsum")

that code had to be running.

I tried with my own PC 8GB RAM, and it works perfectly, but in my VPS i only has 1GB RAM and it always killed the proccess because lack of memory. How can i limit Python Memory Usage so i could run that 2.12GB model?



Solution 1:[1]

UPDATE :

Someone told me to do "emulate" more RAM by using hard drive, and i did this tutorial with my VPS : https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-18-04/

Link above is tutorial how to add SWAP or add more RAM from your Hard Disk.

I added 5GB SWAP and it really run the program, but the speed is sooooooo slow, just like he told me before. even when i write this Answer (About 20 Mins), it still loading the process LMAO.

Thanks for the answer btw.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ken Arya