EagerSession.ResourceCleanupStrategy
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
यह नियंत्रित करता है कि जब TensorFlow संसाधनों की आवश्यकता नहीं रह जाती है तो उन्हें कैसे साफ़ किया जाता है।
EagerSession
के दौरान आवंटित सभी संसाधन सत्र बंद होने पर हटा दिए जाते हैं। आउट-ऑफ़-मेमोरी त्रुटियों को रोकने के लिए, सत्र के दौरान उन संसाधनों को साफ़ करने का भी दृढ़ता से सुझाव दिया गया है। उदाहरण के लिए, m पुनरावृत्तियों के लूप में n संचालन निष्पादित करने से न्यूनतम n*m संसाधन आवंटित होंगे जबकि अधिकांश मामलों में, केवल अंतिम पुनरावृत्ति के संसाधनों का ही उपयोग किया जा रहा है।
जब TensorFlow ऑब्जेक्ट को अब संदर्भित नहीं किया जा रहा है, तो EagerSession
उदाहरणों को अलग-अलग तरीकों से अधिसूचित किया जा सकता है, ताकि वे अपने स्वामित्व वाले किसी भी संसाधन की सफाई के लिए आगे बढ़ सकें।
विरासत में मिली विधियाँ
कक्षा java.lang.Enum से अंतिम पूर्णांक | तुलना करें (ई arg0) |
int यहाँ | तुलना करें (ऑब्जेक्ट arg0) |
अंतिम बूलियन | बराबर (ऑब्जेक्ट arg0) |
अंतिम कक्षा<ई> | getDeclaringClass () |
अंतिम पूर्णांक | हैश कोड () |
अंतिम स्ट्रिंग | नाम () |
अंतिम पूर्णांक | क्रमसूचक () |
डोरी | स्ट्रिंग () |
स्थिर <T Enum<T>> T का विस्तार करता है | valueOf (कक्षा<T> arg0, स्ट्रिंग arg1) |
कक्षा java.lang.Object से बूलियन | बराबर (ऑब्जेक्ट arg0) |
अंतिम कक्षा<?> | गेटक्लास () |
int यहाँ | हैश कोड () |
अंतिम शून्य | सूचित करें () |
अंतिम शून्य | सभी को सूचित करें () |
डोरी | स्ट्रिंग () |
अंतिम शून्य | प्रतीक्षा करें (लंबा arg0, int arg1) |
अंतिम शून्य | प्रतीक्षा करें (लंबा arg0) |
अंतिम शून्य | इंतज़ार () |
इंटरफ़ेस java.lang.Comparable से सार इंट | CompareTo (E Enum<E> arg0 का विस्तार करता है) |
एनम मान
सार्वजनिक स्थैतिक अंतिम EagerSession.ResourceCleanupStrategy IN_BACKGROUND
पृष्ठभूमि में चल रहे नए थ्रेड से अप्रयुक्त संसाधनों की निगरानी करें और हटाएं।
इस कार्य के लिए समर्पित एक अतिरिक्त थ्रेड को शुरू करने और चलाने की कीमत पर, TensorFlow संसाधनों को साफ करने का यह सबसे विश्वसनीय तरीका है। प्रत्येक EagerSession
इंस्टेंस का अपना थ्रेड होता है, जिसे केवल सत्र बंद होने पर ही रोका जाता है।
यह रणनीति डिफ़ॉल्ट रूप से उपयोग की जाती है.
सार्वजनिक स्थैतिक अंतिम EagerSession.ResourceCleanupStrategy ON_SAFE_POINTS
किसी अन्य कार्य को पूरा करने से पहले या बाद में, मौजूदा थ्रेड से अप्रयुक्त संसाधनों की निगरानी करें और हटा दें।
अप्रयुक्त संसाधन तब जारी किए जाते हैं जब TensorFlow लाइब्रेरी में कॉल सफाई के लिए एक सुरक्षित बिंदु पर पहुंच जाती है। यह समकालिक रूप से किया जाता है और उस कॉल को ट्रिगर करने वाले थ्रेड को थोड़े समय के लिए अवरुद्ध कर सकता है।
इस रणनीति का उपयोग केवल तभी किया जाना चाहिए, जब किन्हीं कारणों से, सफाई के लिए कोई अतिरिक्त थ्रेड आवंटित नहीं किया जाना चाहिए। अन्यथा, IN_BACKGROUND
प्राथमिकता दी जानी चाहिए।
सार्वजनिक स्थैतिक अंतिम EagerSession.ResourceCleanupStrategy ON_SESSION_CLOSE
सत्र बंद होने पर ही संसाधन हटाएँ।
सत्र के दौरान आवंटित सभी संसाधन तब तक मेमोरी में बने रहेंगे जब तक कि सत्र स्पष्ट रूप से बंद न हो जाए (या पारंपरिक 'संसाधन के साथ प्रयास करें' तकनीक के माध्यम से)। संसाधन सफ़ाई के लिए कोई अतिरिक्त कार्य करने का प्रयास नहीं किया जाएगा.
यह रणनीति आउट-ऑफ़-मेमोरी त्रुटियों का कारण बन सकती है और इसके उपयोग की अनुशंसा नहीं की जाती है, जब तक कि सत्र का दायरा केवल थोड़ी मात्रा में संचालन निष्पादित करने तक सीमित न हो।
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज के कॉन्टेंट को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट की नीतियां देखें. Java, Oracle का और/या इसके तहत काम करने वाली कंपनियों का एक रजिस्टर किया हुआ ट्रेडमार्क है. कुछ कॉन्टेंट को, numpy license के तहत लाइसेंस मिला है.
आखिरी बार 2025-07-28 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-07-28 (UTC) को अपडेट किया गया."],[],[],null,["# EagerSession.ResourceCleanupStrategy\n\npublic static final enum **EagerSession.ResourceCleanupStrategy** \nControls how TensorFlow resources are cleaned up when they are no longer needed.\n\nAll resources allocated during an `EagerSession` are deleted when the session is\nclosed. To prevent out-of-memory errors, it is also strongly suggest to cleanup those resources\nduring the session. For example, executing n operations in a loop of m iterations will allocate\na minimum of n\\*m resources while in most cases, only resources of the last iteration are still\nbeing used.\n\n`EagerSession` instances can be notified in different ways when TensorFlow objects are\nno longer being referred, so they can proceed to the cleanup of any resources they owned.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Inherited Methods\n\nFrom class java.lang.Enum \n\n|----------------------------------|---------------------------------------|\n| final int | compareTo(E arg0) |\n| int | compareTo(Object arg0) |\n| final boolean | equals(Object arg0) |\n| final Class\\\u003cE\\\u003e | getDeclaringClass() |\n| final int | hashCode() |\n| final String | name() |\n| final int | ordinal() |\n| String | toString() |\n| static \\\u003cT extends Enum\\\u003cT\\\u003e\\\u003e T | valueOf(Class\\\u003cT\\\u003e arg0, String arg1) |\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface java.lang.Comparable \n\n|--------------|-------------------------------------|\n| abstract int | compareTo(E extends Enum\\\u003cE\\\u003e arg0) |\n\nEnum Values\n-----------\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**IN_BACKGROUND**\n\nMonitor and delete unused resources from a new thread running in background.\n\nThis is the most reliable approach to cleanup TensorFlow resources, at the cost of\nstarting and running an additional thread dedicated to this task. Each `EagerSession`\ninstance has its own thread, which is stopped only when the session is closed.\n\nThis strategy is used by default.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**ON_SAFE_POINTS**\n\nMonitor and delete unused resources from existing threads, before or after they complete\nanother task.\n\nUnused resources are released when a call to the TensorFlow library reaches a safe point\nfor cleanup. This is done synchronously and might block for a short period of time the thread\nwho triggered that call.\n\nThis strategy should be used only if, for some reasons, no additional thread should be\nallocated for cleanup. Otherwise, [IN_BACKGROUND](/versions/r2.9/api_docs/java/org/tensorflow/EagerSession.ResourceCleanupStrategy#IN_BACKGROUND) should be preferred.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**ON_SESSION_CLOSE**\n\nOnly delete resources when the session is closed.\n\nAll resources allocated during the session will remained in memory until the session is\nexplicitly closed (or via the traditional \\`try-with-resource\\` technique). No extra task for\nresource cleanup will be attempted.\n\nThis strategy can lead up to out-of-memory errors and its usage is not recommended, unless\nthe scope of the session is limited to execute only a small amount of operations.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]