-
Notifications
You must be signed in to change notification settings - Fork 552
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
Dist models just increase the size of node_modules unnecessarily (and aren't useful) #905
Comments
These should have been stripped out! https://github.com/infinitered/nsfwjs/blob/master/.npmignore#L32 If you send a PR to strip out the model folder ( and essentially the demos ) we can merge it and do a new release. cc: @mazenchami |
I'd love to, but if it's already in the Or maybe it's because of the slash at the beginning, and should just be Btw - there's an outstanding issue that is preventing me from using any new versions - #904 Many thanks! |
#909 should fix the issue with the redundant models folder. On a separate note, you don't have to worry about the bundle size if you are on ESM environment (which you should be on any frontend application), it will bundle all three models but will dynamically load only the one that you load when you call On a CJS environment like a backend, it'll technically load the whole thing, but you'd only call the |
Thank you very much. I'm deploying a Node.JS API through an internal Docker image, and the problem is that doing "npm install" puts all those copies of the models there, increasing the image size :) |
There is a case where all models bundled are the problem - namely using them on Cloudflare Workers. I've tried just to remove models from Is there a way to use just one model - and exclude rest from bundling? EDIT: |
Hello @ambrt 👋 You raise a very valid question. Does #909 solve your issue? 🤔 But I do not think running tensorflow on a CF worker is natively supported as of right now. As you have mentioned in #868 it might be possible to get it to work but I don't think it's an ideal environment for it given the available resources specifically RAM and compute time constraints. Bundling the models into the package means in cases like yours where the size of the build directory matters, you'll have to manually remove the model files from the build directory. The bundlers will dynamically load the model you are using so in an ESM environment it will not load other models but it cannot remove the model files because it obviously has no idea what model you'll be loading at runtime so all 3 models will be included in the build. I'm not sure what bundler you are using and I'm also not very familiar with CF workers, but I think it should be possible to clean up the build directory and remove the model files using a script on However, I do agree this may not be ideal for you. The best solution would be to separate the models into another npm package which would then have to be installed along with the However, this probably will make it difficult for the vast majority of users of this package who'd want to simply install the |
@haZya Thanks for pointing it out. I'll check #909 tomorrow. Indeed there could be a version of A reason is that Cloudflare workers have pretty fast Cache/Storage for static assets. So models could be fetched on the fly, keeping bundle size to a bare minimum. I agree that Cloudflare is not the best environment right now for own models. This could change if they'll introduce GPU servers to the wide public. As for bundler, workers use esbuild under the hood - it's possible to bundle on one's own. Didn't use that option yet but docs say it's possible. |
Hi @haZya Running It seems that it triggers "prebuild" script on installation instead of at bundling time. |
Hey @ambrt It would not have the I have added a |
Using custom esbuild seems to work, for example: |
Now that the models are bundled, with PR #811, the size of "node_modules/nsfwjs" is now 3 x 3 Models bigger.
The modules appear in the following subdirectories:
The 3 models, in these 3 folders.
And, none of them are really usable... because they're in the
.min.js
format.Therefore, I still need to ship my own files, with the actual raw models, in some directory that is not the node_modules.
Is it possible to either remove the bundled models completely, by ignoring them in the build/publish,
or at least ship only ONE version of them, being the raw files?
Thank you very much!
The text was updated successfully, but these errors were encountered: