如何使用时间线分析 GPflow 优化过程?
How to profile GPflow optimization process using timeline?
我正在尝试使用时间线分析 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())
是否有可能在时间轴上也显示优化轨迹?
我已设置:
custom_config.profiling.each_time = True
在每个 运行 之后获取跟踪文件。然后我使用 jq
合并了痕迹:
jq -s '{traceEvents: map(.traceEvents[])}' gpflow_timeline_* >> gpflow_timeline_all.json
@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 生成的单个文件,因此将所有内容合并为一个文件可能会造成混乱。
我正在尝试使用时间线分析 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())
是否有可能在时间轴上也显示优化轨迹?
我已设置:
custom_config.profiling.each_time = True
在每个 运行 之后获取跟踪文件。然后我使用 jq
合并了痕迹:
jq -s '{traceEvents: map(.traceEvents[])}' gpflow_timeline_* >> gpflow_timeline_all.json
@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 生成的单个文件,因此将所有内容合并为一个文件可能会造成混乱。