Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FEAT] Refactor CUSTOM_ARCHITECTURES to provide custom model#1232

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
BritishWerewolf wants to merge1 commit intohuggingface:main
base:main
Choose a base branch
Loading
fromBritishWerewolf:add-custom-model-arch

Conversation

BritishWerewolf
Copy link
Contributor

This PR will allow for a custom model to be provided for any of the custom architectures - providingnull will default toPreTrainedModel.

This came about when I wascreating a new model; I wanted to set it up as an Image Segmentation model.

Below shows how a new architecture can be provided with a specific model, rather thanPreTrainedModel.

/**@type {CustomArchitectures} */constCUSTOM_ARCHITECTURES=newMap([['modnet',[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES,null]],['birefnet',[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES,null]],['isnet',[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES,null]],['u2net',[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES,U2NetModel]],['ben',[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES,null]],]);

Providing nothing will default to PreTrainedModel.
@@ -3363,6 +3363,7 @@ const TASK_ALIASES = Object.freeze({
* @param {T} task The task defining which pipeline will be returned. Currently accepted tasks are:
* - `"audio-classification"`: will return a `AudioClassificationPipeline`.
* - `"automatic-speech-recognition"`: will return a `AutomaticSpeechRecognitionPipeline`.
* - `"background-removal"`: will return a `BackgroundRemovalPipeline`.
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I noticed that we forgot to add the new pipeline to the docblock.

Comment on lines +7920 to 7936
/** @type {CustomArchitectures} */
const CUSTOM_ARCHITECTURES = new Map([
['modnet', MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES],
['birefnet', MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES],
['isnet', MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES],
['ben', MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES],
['modnet',[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES, null]],
['birefnet',[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES, null]],
['isnet',[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES, null]],
['ben',[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES, null]],
]);
for (const [name, mapping] of CUSTOM_ARCHITECTURES.entries()) {
mapping.set(name, ['PreTrainedModel', PreTrainedModel])

for (let [name, [mapping, model]] of CUSTOM_ARCHITECTURES.entries()) {
if (!model) {
model = PreTrainedModel;
}
mapping.set(name, [model.constructor.name, model]);
MODEL_TYPE_MAPPING.set(name, MODEL_TYPES.EncoderOnly);
MODEL_CLASS_TO_NAME_MAPPING.set(PreTrainedModel, name);
MODEL_NAME_TO_CLASS_MAPPING.set(name,PreTrainedModel);
MODEL_CLASS_TO_NAME_MAPPING.set(model, name);
MODEL_NAME_TO_CLASS_MAPPING.set(name,model);
}
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This refactor allows us to specify a custom model for any given architecture.
Currently I haven't changed anything, so they will all default toPreTrainedModel.

@BritishWerewolfBritishWerewolf changed the title[FEAT] Update custom architectures to provide custom model[FEAT] Refactor CUSTOM_ARCHITECTURES to provide custom modelMar 13, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@BritishWerewolf

[8]ページ先頭

©2009-2025 Movatter.jp