Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize memory footprint #32

Open
florent-pajot opened this issue Mar 17, 2023 · 0 comments
Open

Optimize memory footprint #32

florent-pajot opened this issue Mar 17, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@florent-pajot
Copy link
Collaborator

The current implementation is not optimized in terms of memory footprint, I proposed to perform some optimization.

The first one would be to use smaller dtypes. An example of it is optimizing the one hot encoded representation of features (used in

def _search_slices(
). Scikit-learn OneHotEncoder returns sparse matrice with float types:

from sklearn.preprocessing import OneHotEncoder
o = OneHotEncoder()
float_r = o.fit_transform([("a", "b", "c"), ("a", "a", "a")])
print(float_r)
 # <2x5 sparse matrix of type '<class 'numpy.float64'>'
 #   with 6 stored elements in Compressed Sparse Row format>

print(float_r.data.nbytes)
#48

int8_r = r.astype(np.int8)
print(int8_r.data.nbytes)
# 6

And, other typing optimization could be done.

Another potential optimization would be to avoid unecessary copy and force garbage colleciton. For example, in the same _search_slice method:
x_encoded = self._one_hot_encoder.fit_transform(input_x)

Here, input_x is kept but it not used anymore and could be deleted.

@florent-pajot florent-pajot self-assigned this Mar 17, 2023
@florent-pajot florent-pajot added the enhancement New feature or request label Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant