Skip to content

Enhance Memory Optimizer with Dynamic Cost Model for Operation Recomputation #94653

Closed

Description

@aybakanawork

Background

TensorFlow's memory optimizer currently uses a static list to determine which operations are "cheap" to recompute rather than keep in memory. This approach, while functional, leaves significant room for optimization that could improve both memory usage and performance across different models and hardware configurations.

Current implementation in tensorflow/core/grappler/optimizers/memory_optimizer.cc:

std::unordered_set<string> GetCheapToRecomputeOps() {
  std::unordered_set<string> cheap_ops = {"Add", "AddN", "BiasAdd", ...};
  return cheap_ops;
}

Proposed Enhancement

Replace the static list with a dynamic cost model that considers:

  1. Operation Characteristics:

    • Actual computational complexity
    • Memory usage patterns
    • Input/output tensor sizes
    • Operation type-specific metrics
  2. Runtime Factors:

    • Available system memory
    • Hardware capabilities (CPU/GPU/TPU)
    • Current memory pressure
    • Historical execution timing data
  3. Adaptive Decision Making:

    • Cost-benefit ratio calculation for recomputation vs. storage
    • Dynamic thresholds based on system state
    • Learning from actual execution patterns

Expected Benefits

  1. Improved Memory Efficiency: Better decisions about when to recompute vs. store results
  2. Enhanced Performance: More optimal use of available computational resources
  3. Hardware Adaptability: Better adaptation to different hardware configurations
  4. Dynamic Optimization: Responsive to changing runtime conditions
  5. Reduced Memory Pressure: More intelligent memory management for large models

Testing Strategy

  1. Benchmark suite with various model architectures
  2. Memory usage comparisons
  3. Performance impact measurements
  4. Hardware-specific test cases
  5. Edge case validation

Success Metrics

  • Reduced peak memory usage in large models
  • Improved training speed for memory-constrained scenarios
  • Better resource utilization across different hardware configurations

Activity

  1. added
    comp:core
    on Jun 5, 2025
  2. Venkat6871 commented on Jun 11, 2025

    @Venkat6871
    Contributor

    Hi @aybakanawork ,
    Apologies for the delay, and thank you for your contribution. Could you please raise a PR with the changes you are proposing? That will help us better understand and address your needs. For your reference, I am sharing the contribution guide below. Thank you!

  3. added
    stat:contribution welcome
    on Jun 11, 2025
  4. github-actions commented on Jan 31, 2026

    @github-actions

    This issue is stale because it has been open for 180 days with no activity. It will be closed if no further activity occurs. Thank you.

  5. added
    stale
    on Jan 31, 2026
  6. added a commit that references this issue on Feb 2, 2026
    b278456
  7. added 4 commits that reference this issue on Mar 18, 2026
    4d1862b
    e91c9bd
    a86790d
    3e3bd03
  8. added
    awaiting PR merge
    and removed
    stale
    stat:contribution welcome
    on Jul 3, 2026
  9. google-ml-butler commented on Jul 16, 2026

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

awaiting PR mergecomp:coretype:performance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions