def __getattribute__(user_class, attribute_name): # Overriding train in order to minimize the changes necessary in the user # code to go from local to remote execution. # That way, by simply commenting or uncommenting the Train decorator # Model.train() will execute either on the local setup or in kubernetes if attribute_name != 'train' or user_class.is_training_initialized: return super(UserClass, user_class).__getattribute__(attribute_name) if attribute_name == 'train' and not is_runtime_phase(): return super( UserClass, user_class).__getattribute__('_deploy_training') user_class.is_training_initialized = True self.trainer.start_training(user_class) return super(UserClass, user_class).__getattribute__('_noop_attribute')
def __getattribute__(user_object, attribute_name): # Overriding train in order to minimize the changes # necessary in the user code to go from local to remoten't be here probably # execution. # That way, by simply commenting or uncommenting the # Train decorator model.train() will execute either on the local # setup or in kubernetes. if (attribute_name != 'train' or user_object.is_training_initialized): return super(UserClass, user_object).__getattribute__( attribute_name) if attribute_name == 'train' and not utils.is_runtime_phase(): return super(UserClass, user_object).__getattribute__( '_deploy_training') user_object.is_training_initialized = True self._train(user_object) return super(UserClass, user_object).__getattribute__( '_noop_attribute')
def wrapped(): if is_runtime_phase(): return self.serve(func) ast = self.backend.compile_serving_ast(self.image, self.package.name, self.port, self.replicas) self.builder.write_dockerfile(self.package) self.builder.build(self.image) if self.package.publish: self.builder.publish(self.image) def signal_handler(signal, frame): mp.cancel(self.package.name) sys.exit(0) signal.signal(signal.SIGINT, signal_handler) mp.run(ast) logger.warn("Server deployed.") return mp.logs(self.package.name)
import logging import types import redis import os import json import math import numpy as np import time from ..basic import BasicTrainingStrategy from .exploit import Truncation from .explore import Resample, Perturb from fairing.utils import is_runtime_phase #TODO: can we make this class framework agnostic? if is_runtime_phase(): import tensorflow as tf logger = logging.getLogger('fairing') class PopulationBasedTraining(BasicTrainingStrategy): def __init__( self, model_path, population_size, exploit_count, steps_per_exploit, pvc_name, exploiter=Truncation(), explorer=Perturb(),
def test_is_runtime_phase(runtime_phase, monkeypatch): if runtime_phase: monkeypatch.setenv("FAIRING_RUNTIME", True) assert is_runtime_phase() == runtime_phase