tf.config.experimental.reset_memory_stats
Stay organized with collections
Save and categorize content based on your preferences.
Resets the tracked memory stats for the chosen device.
tf.config.experimental.reset_memory_stats(
device
)
This function sets the tracked peak memory for a device to the device's
current memory usage. This allows you to measure the peak memory usage for a
specific part of your program. For example:
if tf.config.list_physical_devices('GPU'):
# Sets the peak memory to the current memory.
tf.config.experimental.reset_memory_stats('GPU:0')
# Creates the first peak memory usage.
x1 = tf.ones(1000 * 1000, dtype=tf.float64)
del x1 # Frees the memory referenced by `x1`.
peak1 = tf.config.experimental.get_memory_info('GPU:0')['peak']
# Sets the peak memory to the current memory again.
tf.config.experimental.reset_memory_stats('GPU:0')
# Creates the second peak memory usage.
x2 = tf.ones(1000 * 1000, dtype=tf.float32)
del x2
peak2 = tf.config.experimental.get_memory_info('GPU:0')['peak']
assert peak2 < peak1 # tf.float32 consumes less memory than tf.float64.
Currently only supports GPU and TPU. If called on a CPU device, an exception
will be raised.
Args |
device
|
Device string to reset the memory stats, e.g. "GPU:0" , "TPU:0" .
See https://www.tensorflow.org/api_docs/python/tf/device for specifying
device strings.
|
Raises |
ValueError
|
No device found with the device name, like '"nonexistent"'.
|
ValueError
|
Invalid device name, like '"GPU"', '"CPU:GPU"', '"CPU:"'.
|
ValueError
|
Multiple devices matched with the device name.
|
ValueError
|
Memory statistics not tracked or clearing memory statistics not
supported, like '"CPU:0"'.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.config.experimental.reset_memory_stats\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/framework/config.py#L620-L658) |\n\nResets the tracked memory stats for the chosen device.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.config.experimental.reset_memory_stats`](https://www.tensorflow.org/api_docs/python/tf/config/experimental/reset_memory_stats)\n\n\u003cbr /\u003e\n\n tf.config.experimental.reset_memory_stats(\n device\n )\n\nThis function sets the tracked peak memory for a device to the device's\ncurrent memory usage. This allows you to measure the peak memory usage for a\nspecific part of your program. For example: \n\n if tf.config.list_physical_devices('GPU'):\n # Sets the peak memory to the current memory.\n tf.config.experimental.reset_memory_stats('GPU:0')\n # Creates the first peak memory usage.\n x1 = tf.ones(1000 * 1000, dtype=tf.float64)\n del x1 # Frees the memory referenced by `x1`.\n peak1 = tf.config.experimental.get_memory_info('GPU:0')['peak']\n # Sets the peak memory to the current memory again.\n tf.config.experimental.reset_memory_stats('GPU:0')\n # Creates the second peak memory usage.\n x2 = tf.ones(1000 * 1000, dtype=tf.float32)\n del x2\n peak2 = tf.config.experimental.get_memory_info('GPU:0')['peak']\n assert peak2 \u003c peak1 # tf.float32 consumes less memory than tf.float64.\n\nCurrently only supports GPU and TPU. If called on a CPU device, an exception\nwill be raised.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `device` | Device string to reset the memory stats, e.g. `\"GPU:0\"`, `\"TPU:0\"`. See https://www.tensorflow.org/api_docs/python/tf/device for specifying device strings. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------------------------------------------------------------|\n| `ValueError` | No device found with the device name, like '\"nonexistent\"'. |\n| `ValueError` | Invalid device name, like '\"GPU\"', '\"CPU:GPU\"', '\"CPU:\"'. |\n| `ValueError` | Multiple devices matched with the device name. |\n| `ValueError` | Memory statistics not tracked or clearing memory statistics not supported, like '\"CPU:0\"'. |\n\n\u003cbr /\u003e"]]