CuPy running out of memory












1














I have been testing the CuPy library and done a simple matrix multiplication using einsum:



C = cp.einsum('pqrs,rs->pq', A, B)


Dimensions of A and B are, (41, 41, 41, 41) (41, 41), receptively. I also checked their sizes, which are 22606088 bytes, 13448 bytes.



While running the code, I am getting the following error message:
OutOfMemoryError: out of memory to allocate 38000834048 bytes (total 38023468032 bytes)


It indicates that I am running out of memory. Is there any option to sent data partially to the device and perform operations in terms of batches?










share|improve this question




















  • 2




    What CuPy version are you using? Could you add the output of cupy.show_config()?
    – Kenichi Maehashi
    Nov 16 at 3:39
















1














I have been testing the CuPy library and done a simple matrix multiplication using einsum:



C = cp.einsum('pqrs,rs->pq', A, B)


Dimensions of A and B are, (41, 41, 41, 41) (41, 41), receptively. I also checked their sizes, which are 22606088 bytes, 13448 bytes.



While running the code, I am getting the following error message:
OutOfMemoryError: out of memory to allocate 38000834048 bytes (total 38023468032 bytes)


It indicates that I am running out of memory. Is there any option to sent data partially to the device and perform operations in terms of batches?










share|improve this question




















  • 2




    What CuPy version are you using? Could you add the output of cupy.show_config()?
    – Kenichi Maehashi
    Nov 16 at 3:39














1












1








1







I have been testing the CuPy library and done a simple matrix multiplication using einsum:



C = cp.einsum('pqrs,rs->pq', A, B)


Dimensions of A and B are, (41, 41, 41, 41) (41, 41), receptively. I also checked their sizes, which are 22606088 bytes, 13448 bytes.



While running the code, I am getting the following error message:
OutOfMemoryError: out of memory to allocate 38000834048 bytes (total 38023468032 bytes)


It indicates that I am running out of memory. Is there any option to sent data partially to the device and perform operations in terms of batches?










share|improve this question















I have been testing the CuPy library and done a simple matrix multiplication using einsum:



C = cp.einsum('pqrs,rs->pq', A, B)


Dimensions of A and B are, (41, 41, 41, 41) (41, 41), receptively. I also checked their sizes, which are 22606088 bytes, 13448 bytes.



While running the code, I am getting the following error message:
OutOfMemoryError: out of memory to allocate 38000834048 bytes (total 38023468032 bytes)


It indicates that I am running out of memory. Is there any option to sent data partially to the device and perform operations in terms of batches?







python chainer cupy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 at 5:21









talonmies

59.1k17128196




59.1k17128196










asked Nov 16 at 2:27









EveSz

162




162








  • 2




    What CuPy version are you using? Could you add the output of cupy.show_config()?
    – Kenichi Maehashi
    Nov 16 at 3:39














  • 2




    What CuPy version are you using? Could you add the output of cupy.show_config()?
    – Kenichi Maehashi
    Nov 16 at 3:39








2




2




What CuPy version are you using? Could you add the output of cupy.show_config()?
– Kenichi Maehashi
Nov 16 at 3:39




What CuPy version are you using? Could you add the output of cupy.show_config()?
– Kenichi Maehashi
Nov 16 at 3:39












1 Answer
1






active

oldest

votes


















0














I think there is no option to send data partially for one-array.



And I faced same issue before, this may be caused because the cupy einsum efficiency is not optimized yet.
https://github.com/cupy/cupy/issues/19#issuecomment-322972682



If you can try replacing your einsum function by using transpose, reshape and matmul etc, please try those.



I guess



C = cp.einsum('pqrs,rs->pq', A, B)


is equivalent to



p, q, r, s = A.shape
A = cp.reshape(A, (p, q, r*s))
B = cp.reshape(B, (1, 1, r*s))
C = cp.sum(A * B, axis=2)





share|improve this answer





















  • You are right, this way works. It looks the CuPy einsum is not optimized. I also noticed that this library does not work if the available memory is excited, what is a huge drawback. Well, we know that GPU cards do not provide to much memory. Have you tried to go around it?
    – EveSz
    Nov 17 at 16:03






  • 1




    I think einsum implementation is updated, I don't know which cupy version you are using but latest version may work more efficiently.
    – corochann
    Nov 18 at 13:21











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330588%2fcupy-running-out-of-memory%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think there is no option to send data partially for one-array.



And I faced same issue before, this may be caused because the cupy einsum efficiency is not optimized yet.
https://github.com/cupy/cupy/issues/19#issuecomment-322972682



If you can try replacing your einsum function by using transpose, reshape and matmul etc, please try those.



I guess



C = cp.einsum('pqrs,rs->pq', A, B)


is equivalent to



p, q, r, s = A.shape
A = cp.reshape(A, (p, q, r*s))
B = cp.reshape(B, (1, 1, r*s))
C = cp.sum(A * B, axis=2)





share|improve this answer





















  • You are right, this way works. It looks the CuPy einsum is not optimized. I also noticed that this library does not work if the available memory is excited, what is a huge drawback. Well, we know that GPU cards do not provide to much memory. Have you tried to go around it?
    – EveSz
    Nov 17 at 16:03






  • 1




    I think einsum implementation is updated, I don't know which cupy version you are using but latest version may work more efficiently.
    – corochann
    Nov 18 at 13:21
















0














I think there is no option to send data partially for one-array.



And I faced same issue before, this may be caused because the cupy einsum efficiency is not optimized yet.
https://github.com/cupy/cupy/issues/19#issuecomment-322972682



If you can try replacing your einsum function by using transpose, reshape and matmul etc, please try those.



I guess



C = cp.einsum('pqrs,rs->pq', A, B)


is equivalent to



p, q, r, s = A.shape
A = cp.reshape(A, (p, q, r*s))
B = cp.reshape(B, (1, 1, r*s))
C = cp.sum(A * B, axis=2)





share|improve this answer





















  • You are right, this way works. It looks the CuPy einsum is not optimized. I also noticed that this library does not work if the available memory is excited, what is a huge drawback. Well, we know that GPU cards do not provide to much memory. Have you tried to go around it?
    – EveSz
    Nov 17 at 16:03






  • 1




    I think einsum implementation is updated, I don't know which cupy version you are using but latest version may work more efficiently.
    – corochann
    Nov 18 at 13:21














0












0








0






I think there is no option to send data partially for one-array.



And I faced same issue before, this may be caused because the cupy einsum efficiency is not optimized yet.
https://github.com/cupy/cupy/issues/19#issuecomment-322972682



If you can try replacing your einsum function by using transpose, reshape and matmul etc, please try those.



I guess



C = cp.einsum('pqrs,rs->pq', A, B)


is equivalent to



p, q, r, s = A.shape
A = cp.reshape(A, (p, q, r*s))
B = cp.reshape(B, (1, 1, r*s))
C = cp.sum(A * B, axis=2)





share|improve this answer












I think there is no option to send data partially for one-array.



And I faced same issue before, this may be caused because the cupy einsum efficiency is not optimized yet.
https://github.com/cupy/cupy/issues/19#issuecomment-322972682



If you can try replacing your einsum function by using transpose, reshape and matmul etc, please try those.



I guess



C = cp.einsum('pqrs,rs->pq', A, B)


is equivalent to



p, q, r, s = A.shape
A = cp.reshape(A, (p, q, r*s))
B = cp.reshape(B, (1, 1, r*s))
C = cp.sum(A * B, axis=2)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 at 2:58









corochann

1,0701618




1,0701618












  • You are right, this way works. It looks the CuPy einsum is not optimized. I also noticed that this library does not work if the available memory is excited, what is a huge drawback. Well, we know that GPU cards do not provide to much memory. Have you tried to go around it?
    – EveSz
    Nov 17 at 16:03






  • 1




    I think einsum implementation is updated, I don't know which cupy version you are using but latest version may work more efficiently.
    – corochann
    Nov 18 at 13:21


















  • You are right, this way works. It looks the CuPy einsum is not optimized. I also noticed that this library does not work if the available memory is excited, what is a huge drawback. Well, we know that GPU cards do not provide to much memory. Have you tried to go around it?
    – EveSz
    Nov 17 at 16:03






  • 1




    I think einsum implementation is updated, I don't know which cupy version you are using but latest version may work more efficiently.
    – corochann
    Nov 18 at 13:21
















You are right, this way works. It looks the CuPy einsum is not optimized. I also noticed that this library does not work if the available memory is excited, what is a huge drawback. Well, we know that GPU cards do not provide to much memory. Have you tried to go around it?
– EveSz
Nov 17 at 16:03




You are right, this way works. It looks the CuPy einsum is not optimized. I also noticed that this library does not work if the available memory is excited, what is a huge drawback. Well, we know that GPU cards do not provide to much memory. Have you tried to go around it?
– EveSz
Nov 17 at 16:03




1




1




I think einsum implementation is updated, I don't know which cupy version you are using but latest version may work more efficiently.
– corochann
Nov 18 at 13:21




I think einsum implementation is updated, I don't know which cupy version you are using but latest version may work more efficiently.
– corochann
Nov 18 at 13:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330588%2fcupy-running-out-of-memory%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?