Пример #1
0
 def test_basic(self):
     """
 Test a basic workflow: load a model, compile and export as shared lib,
 and make predictions
 """
     for model_path, dtrain_path, dtest_path, libname_fmt, \
         expected_prob_path, expected_margin_path, multiclass in \
         [('mushroom/mushroom.model', 'mushroom/agaricus.train',
           'mushroom/agaricus.test', './agaricus{}',
           'mushroom/agaricus.test.prob',
           'mushroom/agaricus.test.margin', False),
          ('dermatology/dermatology.model', 'dermatology/dermatology.train',
           'dermatology/dermatology.test', './dermatology{}',
           'dermatology/dermatology.test.prob',
           'dermatology/dermatology.test.margin', True)]:
         model_path = os.path.join(dpath, model_path)
         model = treelite.Model.load(model_path, model_format='xgboost')
         make_annotation(model=model,
                         dtrain_path=dtrain_path,
                         annotation_path='./annotation.json')
         for use_annotation in ['./annotation.json', None]:
             for use_quantize in [True, False]:
                 run_pipeline_test(
                     model=model,
                     dtest_path=dtest_path,
                     libname_fmt=libname_fmt,
                     expected_prob_path=expected_prob_path,
                     expected_margin_path=expected_margin_path,
                     multiclass=multiclass,
                     use_annotation=use_annotation,
                     use_quantize=use_quantize)
Пример #2
0
 def test_single_inst(self):
     for model_path, dtrain_path, dtest_path, libname_fmt, \
         expected_prob_path, expected_margin_path, multiclass in \
         [('mushroom/mushroom.model', 'mushroom/agaricus.train',
           'mushroom/agaricus.test', './agaricus{}',
           'mushroom/agaricus.test.prob',
           'mushroom/agaricus.test.margin', False),
          ('dermatology/dermatology.model', 'dermatology/dermatology.train',
           'dermatology/dermatology.test', './dermatology{}',
           'dermatology/dermatology.test.prob',
           'dermatology/dermatology.test.margin', True)]:
         model_path = os.path.join(dpath, model_path)
         model = treelite.Model.load(model_path, model_format='xgboost')
         make_annotation(model=model,
                         dtrain_path=dtrain_path,
                         annotation_path='./annotation.json')
         for use_annotation in ['./annotation.json', None]:
             for use_quantize in [True, False]:
                 self.run_pipeline_test(
                     model=model,
                     dtest_path=dtest_path,
                     libname_fmt=libname_fmt,
                     expected_prob_path=expected_prob_path,
                     expected_margin_path=expected_margin_path,
                     multiclass=multiclass,
                     use_annotation=use_annotation,
                     use_quantize=use_quantize)
Пример #3
0
 def test_code_folding(self):
   for model_format, model_path, dtrain_path, dtest_path, libname_fmt, \
       expected_prob_path, expected_margin_path, multiclass, \
       use_parallel_comp in \
       [('xgboost', 'mushroom/mushroom.model', 'mushroom/agaricus.train',
         'mushroom/agaricus.test', './agaricus{}', 'mushroom/agaricus.test.prob',
         'mushroom/agaricus.test.margin', False, None),
        ('xgboost', 'dermatology/dermatology.model',
         'dermatology/dermatology.train', 'dermatology/dermatology.test',
         './dermatology{}', 'dermatology/dermatology.test.prob',
         'dermatology/dermatology.test.margin', True, None),
        ('lightgbm', 'toy_categorical/toy_categorical_model.txt', None,
         'toy_categorical/toy_categorical.test', './toycat{}',
         None, 'toy_categorical/toy_categorical.test.pred', False, 2)]:
     model_path = os.path.join(dpath, model_path)
     model = treelite.Model.load(model_path, model_format=model_format)
     if dtrain_path is not None:
       make_annotation(model=model, dtrain_path=dtrain_path,
                       annotation_path='./annotation.json')
       use_annotation = './annotation.json'
     else:
       use_annotation = None
     for use_quantize in [False, True]:
       for use_code_folding in [1.0, 2.0, 3.0]:
         run_pipeline_test(model=model, dtest_path=dtest_path,
                           libname_fmt=libname_fmt,
                           expected_prob_path=expected_prob_path,
                           expected_margin_path=expected_margin_path,
                           multiclass=multiclass, use_annotation=use_annotation,
                           use_quantize=use_quantize,
                           use_parallel_comp=use_parallel_comp,
                           use_code_folding=use_code_folding)
Пример #4
0
    def test_basic(self):
        """
    Test a basic workflow: load a model, compile and export as shared lib,
    and make predictions
    """

        is_linux = sys.platform.startswith('linux')

        for model_path, dtrain_path, dtest_path, libname_fmt, \
            expected_prob_path, expected_margin_path, multiclass in \
            [('mushroom/mushroom.model', 'mushroom/agaricus.train',
              'mushroom/agaricus.test', './agaricus{}',
              'mushroom/agaricus.test.prob',
              'mushroom/agaricus.test.margin', False),
             ('dermatology/dermatology.model', 'dermatology/dermatology.train',
              'dermatology/dermatology.test', './dermatology{}',
              'dermatology/dermatology.test.prob',
              'dermatology/dermatology.test.margin', True)]:
            model_path = os.path.join(dpath, model_path)
            model = treelite.Model.load(model_path, model_format='xgboost')
            make_annotation(model=model,
                            dtrain_path=dtrain_path,
                            annotation_path='./annotation.json')
            for use_annotation in ['./annotation.json', None]:
                for use_quantize in [True, False]:
                    for use_parallel_comp in [None, 2]:
                        run_pipeline_test(
                            model=model,
                            dtest_path=dtest_path,
                            libname_fmt=libname_fmt,
                            expected_prob_path=expected_prob_path,
                            expected_margin_path=expected_margin_path,
                            multiclass=multiclass,
                            use_annotation=use_annotation,
                            use_quantize=use_quantize,
                            use_parallel_comp=use_parallel_comp)
            for use_elf in [True, False] if is_linux else [False]:
                run_pipeline_test(model=model,
                                  dtest_path=dtest_path,
                                  libname_fmt=libname_fmt,
                                  expected_prob_path=expected_prob_path,
                                  expected_margin_path=expected_margin_path,
                                  multiclass=multiclass,
                                  use_elf=use_elf,
                                  use_compiler='failsafe')
            if not is_linux:
                # Expect to see an exception when using ELF in non-Linux OS
                with pytest.raises(treelite.common.util.TreeliteError):
                    run_pipeline_test(
                        model=model,
                        dtest_path=dtest_path,
                        libname_fmt=libname_fmt,
                        expected_prob_path=expected_prob_path,
                        expected_margin_path=expected_margin_path,
                        multiclass=multiclass,
                        use_elf=True,
                        use_compiler='failsafe')

        # LETOR
        model_path = os.path.join(dpath, 'letor/mq2008.model')
        model = treelite.Model.load(model_path, model_format='xgboost')
        make_annotation(model=model,
                        dtrain_path='letor/mq2008.train',
                        annotation_path='./annotation.json')
        if os_platform() != 'windows':
            run_pipeline_test(
                model=model,
                dtest_path='letor/mq2008.test',
                libname_fmt='./mq2008{}',
                expected_prob_path=None,
                expected_margin_path='letor/mq2008.test.pred',
                multiclass=False,
                use_annotation='./annotation.json',
                use_quantize=1,
                use_parallel_comp=700,
                use_toolchains=[
                    'msvc' if os_platform() == 'windows' else 'gcc'
                ])
        run_pipeline_test(model=model,
                          dtest_path='letor/mq2008.test',
                          libname_fmt='./mq2008{}',
                          expected_prob_path=None,
                          expected_margin_path='letor/mq2008.test.pred',
                          multiclass=False,
                          use_elf=is_linux,
                          use_compiler='failsafe')
Пример #5
0
 def test_basic(self):
     """
 Test a basic workflow: load a model, compile and export as shared lib,
 and make predictions
 """
     for model_path, dtrain_path, dtest_path, libname_fmt, \
         expected_prob_path, expected_margin_path, multiclass in \
         [('mushroom/mushroom.model', 'mushroom/agaricus.train',
           'mushroom/agaricus.test', './agaricus{}',
           'mushroom/agaricus.test.prob',
           'mushroom/agaricus.test.margin', False),
          ('dermatology/dermatology.model', 'dermatology/dermatology.train',
           'dermatology/dermatology.test', './dermatology{}',
           'dermatology/dermatology.test.prob',
           'dermatology/dermatology.test.margin', True)]:
         model_path = os.path.join(dpath, model_path)
         model = treelite.Model.load(model_path, model_format='xgboost')
         make_annotation(model=model,
                         dtrain_path=dtrain_path,
                         annotation_path='./annotation.json')
         for use_annotation in ['./annotation.json', None]:
             for use_quantize in [True, False]:
                 for use_parallel_comp in [None, 2]:
                     run_pipeline_test(
                         model=model,
                         dtest_path=dtest_path,
                         libname_fmt=libname_fmt,
                         expected_prob_path=expected_prob_path,
                         expected_margin_path=expected_margin_path,
                         multiclass=multiclass,
                         use_annotation=use_annotation,
                         use_quantize=use_quantize,
                         use_parallel_comp=use_parallel_comp)
         run_pipeline_test(model=model,
                           dtest_path=dtest_path,
                           libname_fmt=libname_fmt,
                           expected_prob_path=expected_prob_path,
                           expected_margin_path=expected_margin_path,
                           multiclass=multiclass,
                           use_compiler='failsafe')
     # LETOR
     model_path = os.path.join(dpath, 'letor/mq2008.model')
     model = treelite.Model.load(model_path, model_format='xgboost')
     make_annotation(model=model,
                     dtrain_path='letor/mq2008.train',
                     annotation_path='./annotation.json')
     run_pipeline_test(model=model,
                       dtest_path='letor/mq2008.test',
                       libname_fmt='./mq2008{}',
                       expected_prob_path=None,
                       expected_margin_path='letor/mq2008.test.pred',
                       multiclass=False,
                       use_annotation='./annotation.json',
                       use_quantize=1,
                       use_parallel_comp=700,
                       use_toolchains=['gcc'])
     run_pipeline_test(model=model,
                       dtest_path='letor/mq2008.test',
                       libname_fmt='./mq2008{}',
                       expected_prob_path=None,
                       expected_margin_path='letor/mq2008.test.pred',
                       multiclass=False,
                       use_compiler='failsafe')