示例#1
0
def create_task(command, config, context, start=True):
    if not type(command) is str:
        raise TypeError('command type must be str')

    if not type(config) is dict:
        raise TypeError('config type must be dict')

    if 'user_id' in context:
        user_id = context['user_id']
    else:
        raise KeyError('To create task need context user_id')

    with metadata.TaskMetadata().save_context() as task:
        task.id = str(uuid.uuid4())
        task.owner = user_id
        task.command = command
        task.config = config

    if start:
        try:
            start_task(task)
        except gevent.timeout.Timeout:
            with task.save_context():
                task.state = metadata.task.FAILURE
                task.history['error'] = 'Can not send task'

            raise RuntimeError('Can not send task')

    return task
示例#2
0
    def test_test_model(self):
        dataset, architecture, model, task = self.train_model()

        with metadata.TaskMetadata().save_context() as task:
            task.owner = 'u1'
            task.command = 'model.test'
            task.config = {'dataset': dataset.id, 'model': model.id}

        worker.tasks.predict_on_task(task)
示例#3
0
    def create_task_metadata(self, owner):
        document = {'command': 'command', 'config': {}}

        task = metadata.TaskMetadata(**document)
        task.id = str(uuid.uuid4())
        task.owner = owner
        task.command = metadata.task.MODEL_TRAIN
        task.save()

        return task
示例#4
0
    def on_post(self, req, resp):
        user_id = req.context['user']
        logger.debug('Authorize user {id}'.format(id=user_id))

        with metadata.TaskMetadata().save_context() as task:
            task.from_dict(req.media)
            task.id = str(uuid.uuid4())
            task.owner = user_id

        logger.debug('User {uid} create model {did}'.format(uid=user_id,
                                                            did=task.id))

        resp.status = falcon.HTTP_200
        resp.media = {'id': task.id}
    def test_train_no_exceptions(self):
        dataset = self.create_cifar10_dataset()
        architecture = self.create_architecture()
        model = self.create_model(dataset, architecture)

        with metadata.TaskMetadata().save_context() as task:
            task.owner = 'u1'
            task.command = 'model.train'
            task.config = {
                'dataset': dataset.id,
                'model': model.id,
                'epoch': 1,
                'optimizer': {
                    "name": "SGD"
                },
                "loss": "categorical_crossentropy"
            }

        worker.tasks.train_on_task(task)