-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
keras.src vs keras.api design question #20420
Comments
Hi @adrinjalali - Here keras.src is for implementing core functionality of layers, activations etc. While keras.api is seems to be public API use by general users. For importing keras model here you can use |
The issue is not really the difference between keras/keras/src/models/model.py Lines 32 to 33 in 533ea63
Changing the import as you mention, doesn't solve the issue and results in the same import recursion error. Note that for the user, this is not an issue, they simply import form thte public API, which is Also, IIUC, All of this seems rather overcomplicating the codebase / release provess, and my question is the gain we get from having this process. I'm also not sure how a typehint would render if |
If you are in the Keras codebase, you can only import symbols from |
Thanks, yes I realised all that. But it doesn't really answer the question as, why the two folders are separate though. |
Because this lets us define the public API surface separately from the implementation. Exposing all of your internal logic to the user is quite bad practice. We want public APIs to be opt-in only. It's unfortunate that Python packaging does not provide a built-in feature to achieve this. |
This is more of a question for me to better understand the codebase.
Working on #20399 , I realised since there's a distinction between
keras.src
andkeras.api
(which is exposed askeras
in the end), makes it impossible to do certain things.For instance, if you want to typehint an input as
keras.Model
, then you'd need to do aimport keras.Model
kinda thing. But that results in a circular import issue along these lines:Checking the codebase, I realise typehints are not a thing we do here, so I'll remove them, but it still begs the question, what are the gains with the separation of the two folders, which adds quite a bit of complexity. In other projects, we tend to have a leading
_
on file names, and__init__.py
exposes what needs to be public on the user API level.The text was updated successfully, but these errors were encountered: