Exemplo n.º 1
0
def monitor_task(asset_id, producer):
    task_declaration = TaskDeclaration.get(asset_id, db=producer.db, encryption=producer.encryption)
    logger.info('{} sate {}'.format(task_declaration, task_declaration.state))
    while task_declaration.state != TaskDeclaration.State.FAILED:
        print_task_declaration(task_declaration)

        time.sleep(3)
        task_declaration = TaskDeclaration.get(asset_id, db=producer.db, encryption=producer.encryption)
        if task_declaration.state == TaskDeclaration.State.COMPLETED:
            print_task_declaration(task_declaration)
            break
Exemplo n.º 2
0
    def train_task(self, asset_id):
        while True:
            task_declaration = TaskDeclaration.get(asset_id, db=self.db, encryption=self.encryption)
            if task_declaration.in_finished_state:
                break

            self._process_task_declaration(task_declaration)
            time.sleep(settings.PRODUCER_PROCESS_INTERVAL)
Exemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser(description='Produce Task')

    parser.add_argument('-c', '--command', required=True, metavar='KEY', help='add|stop|cancel|issue|deposit|monitor')
    parser.add_argument('-k', '--key', default="producer", metavar='KEY', help='RSA key name')
    parser.add_argument('-n', '--name', default='mnist_mlp', metavar='NAME', help='model name')
    parser.add_argument('-p', '--path', default='examples/torch/mnist/cnn.py', metavar='PATH', help='model path')
    parser.add_argument('-train', '--dataset_train', default='QmP9KUr8Y6HxNoBNM8zakxC65diYWHG2VBRhPHYnT5uWZT', metavar='dataset_train', help='dataset dir')
    parser.add_argument('-test', '--dataset_test', default='QmRL93gvYRypqWs1wpzR8S6kvoGPxeP12v8RbTAJWDsQaK', metavar='dataset_test', help='dataset dir')
    parser.add_argument('-w', '--workers', default=1, type=int, metavar='WORKERS', help='workers count')
    parser.add_argument('-v', '--verifiers', default=1, type=int, metavar='VERIFIERS', help='verifiers count')
    parser.add_argument('-b', '--batch', default=128, type=int, metavar='BATCH_SIZE', help='batch size')
    parser.add_argument('-e', '--epochs', default=3, type=int, metavar='EPOCHS', help='epochs')
    parser.add_argument('-ei', '--epochs_in_iteration', default=1, type=int, metavar='EPOCHS IN ITERATION', help='epochs in iteration')
    parser.add_argument('-l', '--local', default=0, type=int, metavar='LOCAL', help='train model local')
    parser.add_argument('-t', '--task', default=None, type=str, metavar='TASK_ID', help='task declaration asset id')
    parser.add_argument('-eth', '--eth', default=None, type=float, metavar='ETH', help='ETH for deposit or issue')

    args = parser.parse_args()

    if args.command == 'add':
        if args.local:
            train_local(
                train_dir=args.dataset_train, test_dir=args.dataset_test,
                model_path=args.path, batch_size=args.batch, epochs=args.epochs
            )
        else:
            train_remote(
                train_ipfs=args.dataset_train, test_ipfs=args.dataset_test,
                args=args
            )
        return

    producer = load_producer()
    if not args.task:
        print('task is not specified, arg: -t')
        return

    if args.command == 'cancel':
        td = TaskDeclaration.get(args.task, db=producer.db, encryption=producer.encryption)
        td.state = TaskDeclaration.State.FAILED
        td.save()
        print('Canceled {}'.format(td))
        return

    if args.command == 'stop':
        td = TaskDeclaration.get(args.task, db=producer.db, encryption=producer.encryption)
        td.state = TaskDeclaration.State.COMPLETED
        td.save()
        print('Stopped {}'.format(td))
        return

    if args.command == 'monitor':
        monitor_task(args.task, producer)
        return

    if args.command == 'issue':
        if not args.eth:
            print('balance is not specified, arg: --eth')
            return

        encrypted_key, password = load_wallet_credentials(account_address_var_name='PRODUCER_ACCOUNT_ADDRESS')
        NodeContractInfo.configure(encrypted_key, password)
        task_declaration = TaskDeclaration.get(args.task, db=producer.db, encryption=producer.encryption)
        poa_wrapper.issue_job(task_declaration, args.eth)
        return

    if args.command == 'deposit':
        if not args.eth:
            print('balance is not specified, arg: --eth')
            return

        encrypted_key, password = load_wallet_credentials(account_address_var_name='PRODUCER_ACCOUNT_ADDRESS')
        NodeContractInfo.configure(encrypted_key, password)
        task_declaration = TaskDeclaration.get(args.task, db=producer.db, encryption=producer.encryption)
        poa_wrapper.deposit(task_declaration, args.eth)
        return
Exemplo n.º 4
0
 def task_declaration(self):
     from tatau_core.models import TaskDeclaration
     return TaskDeclaration.get(self.task_declaration_id,
                                db=self.db,
                                encryption=self.encryption)