machinelearning icon indicating copy to clipboard operation
machinelearning copied to clipboard

Predict hangs indefinetly

Open cosmincatalin opened this issue 8 years ago • 7 comments

System information

  • OS version/distro: Mac OS X 10.13
  • .NET Version (eg., dotnet --info): 2.0.5

Issue

  • I have a .csv file with data that I use for individual predictions. I use a FastTreeRegressor model loaded from disk. I make individual predictions and not batch predictions because I need the absolute error histogram. At first, predicting works fine, but then, after what appears to be a random number of executions, the Predict method hangs without anything else happening.
  • I expect either Predict failing with some Exception, or better, fail for the same example or, even better, Predict to work for all my examples, which it should.

By random I mean that I have a few million examples I have to go through, but predicting stops anywhere between after a few hundreds predictions or at best after a few thousands.

Source code / logs

The stripped down source code for Program.cs. Note that I have also tried with version 0.2

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.ML;
using PredictionModelling;

namespace PredictionMetrics
{
    class Program
    {

        static async Task Main(string[] args)
        {
            foreach (string culture in cultures)
            {
                var model = await PredictionModel.ReadAsync<Data, DataPrediction>("model.zip");
                StreamReader file = new StreamReader("test.csv");

                file.ReadLine(); // This is for the header

                string line;

                using (StreamWriter outputFile = new StreamWriter("test-predictions.csv"))
                {
                    var i = 0;
                    outputFile.WriteLine($"actual-value,predicted-value");
                    while ((line = file.ReadLine()) != null)
                    {
                        var data = line.Split(new[] { ',' });
                        var data = new Data()
                        {
                            Feature0 = float.Parse(data[0]),
                            Feature1 = float.Parse(data[1])
                        };
                        var csvLine = $"{data[2]},{model.Predict(data).Value}";
                        outputFile.WriteLine(csvLine);
                        i++;
                        if (i % 100 == 0)
                        {
                            outputFile.Flush();
                        }
                    }
                }
                file.Close();
            }
        }
    }
}

cosmincatalin avatar Jun 10 '18 18:06 cosmincatalin

Cosmin, Do you happen to have any filters in your trained pipeline? Sometimes, if you filter the input row during training, the prediction engine would also filter rows to score and that can stall the pipeline. Ideally, the trained model does not have any filter transforms and all filtering is done before training. For example, if you have missing values it is good idea to replace the NAFilter with NAHandle transform.

glebuk avatar Jun 15 '18 23:06 glebuk

I do not have any filters. The model pipeline looks like this:

var pipeline = new LearningPipeline();
pipeline.Add(new TextLoader<SearchesData>(DataPath, useHeader: true, separator: ","));
pipeline.Add(new ColumnCopier(("Value", "Label")));
pipeline.Add(new ColumnConcatenator("Features", "Feature1", "Feature2"));
pipeline.Add(new FastTreeRegressor() { DiskTranspose = true });

cosmincatalin avatar Jun 18 '18 15:06 cosmincatalin

The API has changed since this bug was filed, @shmoradims can you verify if this is still valid.

shauheen avatar Nov 27 '18 22:11 shauheen

@cosmincatalin , could you please provide your csv data file for repro? thanks.

shmoradims avatar Nov 28 '18 18:11 shmoradims

@shmoradims , unfortunately I have moved on and I do not have the test data any moe. But I can tell you there were around 20 million samples with 18 numerical features. I'm sure that no matter what numbers you put in there it's going to be similar to my experiment.

Now, the pattern outlined above is bad, because instead of predicting in batches, I was predicting one by one. This is obviously less than ideal, but it shouldn't break, and if it breaks there should be an exception. I now use batches, so the issue is of no interest to me anymore, but I though I'd leave it open anyway so that a potential problem can be found.

cosmincatalin avatar Nov 29 '18 08:11 cosmincatalin

Thanks @cosmincatalin.

@yaeldekel we should have some click dataset similar to above for repro.

shmoradims avatar Nov 29 '18 20:11 shmoradims

This issue seems to have happened with the old API. We have the new API now that you should use and provide a repro, until then I will close this issue.

codemzs avatar Jun 30 '19 02:06 codemzs