3
$\begingroup$

I am packaging my model for deployment in aws lambda which has a size limit of 250mb for all dependencies.

Sklearn, if you include its dependencies of numpy and scipy is a huge package.

Are there any alternatives to sklearn that don't require scipy that are smaller than sklearn?

Thanks!

$\endgroup$

1 Answer 1

1
$\begingroup$

Did you check tinynumpy?

Anyway, I rarely found alternatives to famous packages (except scikit-image instead of opencv). What usually works for me is:

  1. Slim the model as much as I can (e.g. weights quantization)
  2. Check in the code which functions I use from each module. Once I have a list of them, I retrieve the corresponding python files and get rid of the rest
  3. Try to split my process in multiple functions (e.g. one function to perform data processing, one function where to implement the model and make the inference)

The second point is crucial. In my experience, one rarely needs entire packages.

However, depending on the case, it could also be that AWS Lambda does not fit your needs.

$\endgroup$
3
  • $\begingroup$ yea that makes sense. I am only using logistic regression, so I'm pretty sure I can remove entire folders from the directory. I guess I'll try to do that using the serverless framework. No idea what weights quantization is so I'll skip that haha. I think multiple lambda funcs is hard bc I don't know how to do that with serverless but I'll try that next. $\endgroup$
    – coderboi
    Jul 4, 2020 at 21:00
  • $\begingroup$ Do you know how to exclude certain directories within serverless? So far I'm including sklearn/**, and excluding ./**. Don't know how to include sklearn/** and exclude specific models within sklearn. $\endgroup$
    – coderboi
    Jul 4, 2020 at 21:06
  • $\begingroup$ For the serverless thing, I don't know honestly, but maybe this can help. The weights quantization reduces the digits in weights: from float32 to float16, or even from float to int form. Accuracy usually does not change significantly. $\endgroup$
    – dapetillo
    Jul 5, 2020 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.