Skip to content

refactor: Change model constants to preset objects#477

Merged
jakmro merged 20 commits intomainfrom
@ms/refactor-model-constants
Aug 5, 2025
Merged

refactor: Change model constants to preset objects#477
jakmro merged 20 commits intomainfrom
@ms/refactor-model-constants

Conversation

@jakmro
Copy link
Copy Markdown
Contributor

@jakmro jakmro commented Jul 29, 2025

Description

Change model constants to preset objects

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improves or adds clarity to existing documentation)

Tested on

  • iOS
  • Android

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes generate no new warnings

@jakmro jakmro self-assigned this Jul 31, 2025
@jakmro jakmro added this to the v0.5.0 milestone Jul 31, 2025
@jakmro jakmro linked an issue Jul 31, 2025 that may be closed by this pull request
@jakmro jakmro marked this pull request as ready for review August 1, 2025 06:53
@jakmro jakmro requested review from chmjkb and mkopcins August 1, 2025 06:54
@jakmro jakmro force-pushed the @ms/refactor-model-constants branch from a7332ab to 21f9178 Compare August 4, 2025 09:49
}) {
async load(
model: {
modelName: AvailableModels;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a note here: it seems counterintuitive to me why we're doing this modelName thing here, but we don't do it for LLMs or other models.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

modelName is required for S2T to select the right strategy

Comment on lines +33 to +35
modelSource: model.modelSource,
tokenizerSource: model.tokenizerSource,
tokenizerConfigSource: model.tokenizerConfigSource,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can't we unpack model here?

Comment on lines +84 to +88
_model,
model.modelName,
model.encoderSource,
model.decoderSource,
model.tokenizerSource,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Im not sure if i like the naming here, at a first glance i can't figure out the difference between _model and model, i guess this also applies to other code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

useRef will be used inside this hook, so the variable name will be updated to something like moduleRef

const DETECTOR_CRAFT_800_MODEL = `${URL_PREFIX}-detector-craft/${VERSION_TAG}/xnnpack/xnnpack_craft_800.pte`;
const DETECTOR_CRAFT_320_MODEL = `${URL_PREFIX}-detector-craft/${VERSION_TAG}/xnnpack/xnnpack_craft_320.pte`;

const createHFRecognizerDownloadUrl = (alphabet: string, size: number) =>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we narrow down the types here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Im changing this in my PR so i guess you can revert it :D

Comment thread docs/docs/03-typescript-api/02-computer-vision/VerticalOCRModule.md
Comment thread docs/docs/03-typescript-api/02-computer-vision/VerticalOCRModule.md
@jakmro jakmro merged commit 212a821 into main Aug 5, 2025
3 checks passed
@jakmro jakmro deleted the @ms/refactor-model-constants branch August 5, 2025 11:40
mkopcins pushed a commit that referenced this pull request Oct 15, 2025
## Description

Change model constants to preset objects

### Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Documentation update (improves or adds clarity to existing
documentation)

### Tested on

- [x] iOS
- [ ] Android

### Checklist

- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have updated the documentation accordingly
- [x] My changes generate no new warnings

---------

Co-authored-by: Mateusz Sluszniak <sluszmat@amazon.com>
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.

Make loading models easier

2 participants