Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to profile the memoryProfileSnapshots more than 1000? #684

Open
TKH666 opened this issue Sep 11, 2023 · 0 comments
Open

How to profile the memoryProfileSnapshots more than 1000? #684

TKH666 opened this issue Sep 11, 2023 · 0 comments

Comments

@TKH666
Copy link

TKH666 commented Sep 11, 2023

I want to profile the memory usage for all op during training. Here is the code for profiling, But I found the result of profiling only records 1000 snapshots of memory allocation/deallocation. How to profile the memoryProfileSnapshots more than 1000?
`loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)

@tf.function
def train_step(x, y):
    with tf.GradientTape() as tape:
        y_pred = model(x, training=True)
        loss = loss_fn(y, y_pred)
    gradients = tape.gradient(loss, model.trainable_weights)
    return gradients

# dummy training data
x = tf.random.normal((batch_size, input_shape[0], input_shape[1], input_shape[2]))
y = tf.ones((batch_size,))

print("Warmup...")
for k in tqdm(range(1)):
    train_step(x, y)

t0 = time.time()

print("Profiling the model...")
tf.profiler.experimental.start(logdir)
for k in range(num_iterations):
    with tf.profiler.experimental.Trace('train', step_num=k):
        train_step(x, y)
tf.profiler.experimental.stop()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant