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

better snippets for KerasHub models #1021

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

martin-gorner
Copy link
Contributor

Added better "use this model" snippets for KerasHub models with:

  • The base class to instantiate when loading the model from_preset
  • the generate() function if any
  • A link to the keras.io documentation of the model
  • alternative snippets for loading the components of the model (Tokenizer, etc)

The data for this comes from parsing task.json, and if not available, config.json and tokenizer.json as well as the pipeline_tag in metadata. The parsing is done in the model repo code.

Screenshot attached for Llama3
Screenshot 2024-11-12 at 05 18 24

@martin-gorner
Copy link
Contributor Author

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments. Hopefully the logic can be simplified if KerasHub stabilizes its structure

Comment on lines +69 to +78
keras_hub_task_json?: {
class_name: string;
alt_class_names?: string[];
};
keras_hub_config_json?: {
class_name: string;
};
keras_hub_tokenizer_json?: {
class_name: string;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slight preference for a more concise

Suggested change
keras_hub_task_json?: {
class_name: string;
alt_class_names?: string[];
};
keras_hub_config_json?: {
class_name: string;
};
keras_hub_tokenizer_json?: {
class_name: string;
};
keras_hub?: {
// relevant task.json content
};

From what I understand, task.json is the future-proof way of getting this info correctly. And getting things from config.json/tokenizer.json is more of a default for previous models up to now. Is my assumption correct or not? If that's the case, then let's focus on parsing only task.json to only promote the "correct" way.

In any case (no matter if the config comes from task.json, config.json or tokenizer.json) I think that having a single field with nested values is better rather than exposing 3 different high-level fields related to keras_hub.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a look at this recent keras-hub model (https://huggingface.co/evandrarf/health-care-gemma2-kagglex/tree/main), I can see that task.json, config.json, tokenizers.json and preprocessor.json are all set. And the content of task.json is strictly a superset of the other 3. Do you know if other files are kept for backward compatbility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you that standardizing on a single config file would be the best. Let me ask the keras team?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matt on the Keras team responded. task.json is not always present and that is by design and not a legacy thing. I recommend we deploy the currently implemented logic while we continue the discussion with Matt and possibly simplify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather wait for a simplification before merging except if it's time-sensitive

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes and imo we can influence the standardization by supporting the simpler / single-version version that Wauplin mentions

Comment on lines +407 to +411
let class_name =
// If the model has a task.json config, then the base Task class is known
model.config?.keras_hub_task_json?.class_name ??
// If only a config.json is present, the base class will be a "backbone"
model.config?.keras_hub_config_json?.class_name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my comment above, if we can get rid of some logic by parsing only task.json, that would be for the best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants