tensorflow 源码解读---容错机制

tensorflow 的容错机制就是,没有容错机制。一旦计算的某个环节出错,就取消所有的计算。但是,tensorflow 是并行的设计(多进程或多线程),即使一个线程的计算出错,也要存在一种机制来取消其他线程正在运行的计算。以下我结合单机执行的源码,来分析一下这个功能的实现。主要追踪了tensorflow\core\common_runtime\direct_session.cc、tensorflow\core\common_runtime\excutor.cc、tensorflow\core\common_runtime\cancellation.cc等几个源文件。

取消正在运行的计算主要由tensorflow\core\common_runtime\cancellation.cc里的CancellationManager类实现的。

CancellationManager 是提供了一种callback ***制。一个op开始运行时,向CancellationManager register cancel callback,结束运行时deregister。每一次session.run(),都会创建一个CancellationManager 对象step_cancellation_manager。

direct_session.cc

tensorflow 源码解读---容错机制

step_cancellation_manager  的引用会通过args传递到ExcutorState 对象。

direct_session.cc

tensorflow 源码解读---容错机制

 

excutor.cc

tensorflow 源码解读---容错机制

在excutor.cc NodeDown 里,如果一个op 计算出错,cancellation_manager_的StartCancel 方法会被触发,取消这个step 的所有的excutor 的所以outstanding op,计算终止。

excutor.cc

tensorflow 源码解读---容错机制

 

随着计算节点的cancel, num_outstanding_ops_ 会因为 !s.ok() 而不断地减小,直到0。

tensorflow 源码解读---容错机制

相关文章:

  • 2021-12-30
  • 2022-02-14
  • 2021-04-11
  • 2021-05-02
  • 2022-03-06
  • 2022-03-06
猜你喜欢
  • 2023-03-21
  • 2021-06-01
  • 2021-08-17
  • 2021-10-08
  • 2021-12-17
  • 2021-11-17
相关资源
相似解决方案