stormlog.tensorflow.context_profiler

TensorFlow Context Profiling

Functions

clear_global_profiler()

Clear global profiler state.

clear_profiles()

Reset profiling data without discarding the global profiler.

get_global_profiler()

Get or create global profiler instance.

get_profile_summaries([limit])

Return aggregated profiling summaries for recent functions/contexts.

profile_context([name, profiler])

Context manager for profiling code blocks.

profile_function([func, profiler, name])

Decorator to profile function memory usage.

profile_keras_training(model, x_train, y_train)

Profile Keras model training.

profile_model(model[, profiler])

Profile all layers in a TensorFlow model.

set_global_profiler(profiler)

Set global profiler instance.

Classes

ProfiledLayer(layer[, profiler, name])

Wrapper for TensorFlow layers with automatic profiling.

TensorFlowProfiler([device])

High-level TensorFlow profiling interface.

stormlog.tensorflow.context_profiler.get_global_profiler()[source]

Get or create global profiler instance.

Return type:

TFMemoryProfiler

stormlog.tensorflow.context_profiler.set_global_profiler(profiler)[source]

Set global profiler instance.

Parameters:

profiler (TFMemoryProfiler)

Return type:

None

stormlog.tensorflow.context_profiler.profile_function(func=None, *, profiler=None, name=None)[source]

Decorator to profile function memory usage.

Parameters:
  • func (F | None) – Function to profile

  • profiler (TFMemoryProfiler | None) – Profiler instance (uses global if None)

  • name (str | None) – Custom name for profiling

Return type:

Callable[[F], F] | F

stormlog.tensorflow.context_profiler.profile_context(name='context', profiler=None)[source]

Context manager for profiling code blocks.

Parameters:
  • name (str) – Name for the profiling context

  • profiler (TFMemoryProfiler | None) – Profiler instance (uses global if None)

Return type:

Iterator[None]

class stormlog.tensorflow.context_profiler.ProfiledLayer(layer, profiler=None, name=None)[source]

Bases: object

Wrapper for TensorFlow layers with automatic profiling.

Parameters:
stormlog.tensorflow.context_profiler.profile_model(model, profiler=None)[source]

Profile all layers in a TensorFlow model.

Parameters:
  • model (Any) – TensorFlow model

  • profiler (TFMemoryProfiler | None) – Profiler instance

Returns:

Model with profiled layers

Return type:

Any

class stormlog.tensorflow.context_profiler.TensorFlowProfiler(device=None)[source]

Bases: object

High-level TensorFlow profiling interface.

Parameters:

device (str | None)

profile_training(model, dataset, epochs=1, steps_per_epoch=None)[source]

Profile model training.

Parameters:
  • model (Any) – TensorFlow model

  • dataset (Any) – Training dataset

  • epochs (int) – Number of epochs

  • steps_per_epoch (int | None) – Steps per epoch

Return type:

None

profile_inference(model, data, batch_size=32)[source]

Profile model inference.

Parameters:
  • model (Any) – TensorFlow model

  • data (Any) – Input data

  • batch_size (int) – Batch size for inference

Return type:

None

get_results()[source]

Get profiling results.

Return type:

Any

reset()[source]

Reset profiler state.

Return type:

None

stormlog.tensorflow.context_profiler.profile_keras_training(model, x_train, y_train, epochs=1, batch_size=32, validation_data=None, profiler=None)[source]

Profile Keras model training.

Parameters:
  • model (Any) – Keras model

  • x_train (Any) – Training data

  • y_train (Any) – Training labels

  • epochs (int) – Number of epochs

  • batch_size (int) – Batch size

  • validation_data (Any | None) – Validation data tuple (x_val, y_val)

  • profiler (TFMemoryProfiler | None) – Profiler instance

Return type:

None

stormlog.tensorflow.context_profiler.clear_global_profiler()[source]

Clear global profiler state.

Return type:

None

stormlog.tensorflow.context_profiler.clear_profiles()[source]

Reset profiling data without discarding the global profiler.

Return type:

None

stormlog.tensorflow.context_profiler.get_profile_summaries(limit=None)[source]

Return aggregated profiling summaries for recent functions/contexts.

Parameters:

limit (int | None)

Return type:

List[Dict[str, Any]]