mirror of
https://github.com/wassname/ray.git
synced 2026-07-12 01:57:10 +08:00
[Tune] Add export_formats option to export policy graphs (#3868)
In earlier PRs, PR#3585 and PR#3637, export_policy_model and export_policy_checkpoint were introduced for users to export TensorFlow model and checkpoint. For Ray Tune users, these APIs are not accessible through YAML configurations. In this pull request, export_formats option is provided to enable users to choose the desired export format.
This commit is contained in:
committed by
Richard Liaw
parent
b9eed2e86c
commit
1302fafc0b
@@ -331,6 +331,23 @@ class Trainable(object):
|
||||
self.restore(checkpoint_path)
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
def export_model(self, export_formats, export_dir=None):
|
||||
"""Exports model based on export_formats.
|
||||
|
||||
Subclasses should override _export_model() to actually
|
||||
export model to local directory.
|
||||
|
||||
Args:
|
||||
export_formats (list): List of formats that should be exported.
|
||||
export_dir (str): Optional dir to place the exported model.
|
||||
Defaults to self.logdir.
|
||||
|
||||
Return:
|
||||
A dict that maps ExportFormats to successfully exported models.
|
||||
"""
|
||||
export_dir = export_dir or self.logdir
|
||||
return self._export_model(export_formats, export_dir)
|
||||
|
||||
def reset_config(self, new_config):
|
||||
"""Resets configuration without restarting the trial.
|
||||
|
||||
@@ -402,6 +419,18 @@ class Trainable(object):
|
||||
"""Subclasses should override this for any cleanup on stop."""
|
||||
pass
|
||||
|
||||
def _export_model(self, export_formats, export_dir):
|
||||
"""Subclasses should override this to export model.
|
||||
|
||||
Args:
|
||||
export_formats (list): List of formats that should be exported.
|
||||
export_dir (str): Directory to place exported models.
|
||||
|
||||
Return:
|
||||
A dict that maps ExportFormats to successfully exported models.
|
||||
"""
|
||||
return {}
|
||||
|
||||
|
||||
def wrap_function(train_func):
|
||||
from ray.tune.function_runner import FunctionRunner
|
||||
|
||||
Reference in New Issue
Block a user