我在google cloud ML引擎中运行大型分布式Tensorflow模型。我想使用带GPU的机器。 我的图由输入/数据读取器功能和计算部分两部分组成。
我希望将变量放在PS任务中,CPU中的输入部分和GPU上的计算部分。
函数tf.train.replica_device_setter
自动将变量放在PS服务器中。
这就是我的代码:
with tf.device(tf.train.replica_device_setter(cluster=cluster_spec)):
input_tensors = model.input_fn(...)
output_tensors = model.model_fn(input_tensors, ...)
是否可以将tf.device()
与replica_device_setter()
一起使用,如:
with tf.device(tf.train.replica_device_setter(cluster=cluster_spec)):
with tf.device('/cpu:0')
input_tensors = model.input_fn(...)
with tf.device('/gpu:0')
tensor_dict = model.model_fn(input_tensors, ...)
是否会覆盖replica_divice_setter()
并且变量没有放在PS服务器中?
此外,由于群集中的设备名称类似job:master/replica:0/task:0/gpu:0
,我该如何对Tensorflow tf.device(whatever/gpu:0)
说?
答案 0 :(得分:3)
tf.train.replica_device_setter
块中除变量之外的任何操作都会自动固定到public class FilterBottomSheet extends BottomSheetDialogFragment implements View.OnClickListener {
private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {
@Override public void onStateChanged(@NonNull View bottomSheet,int newState){
if(newState==BottomSheetBehavior.STATE_HIDDEN) {
dismiss();
}
}
}
@Override public void onSlide(@NonNull View bottomSheet,float slideOffset){}};
@SuppressLint("RestrictedApi")
@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
View contentView = View.inflate(getContext(), R.layout.bottom_sheet_filter, null);
dialog.setContentView(contentView);
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent())
.getLayoutParams();
CoordinatorLayout.Behavior behavior = params.getBehavior();
if (behavior != null && behavior instanceof BottomSheetBehavior) {
((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btnDoAction:
fillActionInterface("TEST");
dismiss();
break;
}
}
public OnResponseListener responseListener;
private void fillActionInterface(String message) {
if (responseListener != null) {
responseListener.onData(200, message);
}
}
}
,这将默认为由" worker"中的第一个任务管理的第一个设备。工作。
您可以使用嵌入式设备块将其固定到其他设备(或任务):
"/job:worker"