我正在尝试使用时间轴分析GPflow,并使用chrome跟踪对其进行可视化。但是跟踪似乎并未显示优化过程(仅模型构建和预测)。我定义了一个自定义配置:
custom_config = gpflow.settings.get_settings()
custom_config.profiling.output_file_name = 'gpflow_timeline'
custom_config.profiling.dump_timeline = True
并尝试在优化后做出简单的预测:
with gpflow.settings.temp_settings(custom_config), gpflow.session_manager.get_session().as_default():
k = gpflow.kernels.RBF()
m = gpflow.models.GPR(X_train, y_train, kern=k)
run_adam(m, lr=0.1, iterations=100, callback=__PrintAction(m, 'GPR with Adam'))
mean, var = m.predict_y(X_test)
其中Adam优化器定义为:
class __PrintAction(Action):
def __init__(self, model, text):
self.model = model
self.text = text
def run(self, ctx):
likelihood = ctx.session.run(self.model.likelihood_tensor)
print('{}: iteration {} likelihood {:.4f}'.format(self.text, ctx.iteration, likelihood))
def run_adam(model, lr, iterations, callback=None):
adam = gpflow.train.AdamOptimizer(lr).make_optimize_action(model)
actions = [adam] if callback is None else [adam, callback]
loop = Loop(actions, stop=iterations)()
model.anchor(model.enquire_session())
是否还可以在时间轴上显示优化跟踪?
答案 0 :(得分:0)
我已设置:
custom_config.profiling.each_time = True
在每次运行后获取跟踪文件。然后,我使用jq
合并了跟踪:
jq -s '{traceEvents: map(.traceEvents[])}' gpflow_timeline_* >> gpflow_timeline_all.json
答案 1 :(得分:0)
扩展到@tadejk答案:
您可以改为在GPflow / gpflow项目文件夹中修改gpflowrc
,或在运行代码并在其中调整性能分析参数的文件夹中创建它。
[logging]
# possible levels: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET
level = WARNING
[verbosity]
tf_compile_verb = False
[dtypes]
float_type = float64
int_type = int32
[numerics]
jitter_level = 1e-6
# quadrature can be set to: allow, warn, error
ekern_quadrature = warn
[profiling]
dump_timeline = False
dump_tensorboard = False
output_file_name = timeline
output_directory = ./
each_time = False
[session]
intra_op_parallelism_threads = 0
inter_op_parallelism_threads = 0
不确定100%,但是将所有内容合并到一个json文件中可能不是一个好主意。由session.run生成的单个文件,因此将所有内容合并为一个文件可能会搞砸。