-
Notifications
You must be signed in to change notification settings - Fork 60
feat: build with executorch 1.0 (#638) #693
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
655dfb6
Initial attempts - replaced libs & headers
IgorSwat a2bdfc5
fix LLM runner
IgorSwat b08edd1
fix OCR models
IgorSwat 76e74ea
Fix index conversions on Android
IgorSwat 3f3bb25
Improve model generation config setup
IgorSwat ef5b92e
Merge branch 'main' of https://github.com/software-mansion/react-nati…
IgorSwat 6640af1
Rebuild ios libs with OCR fix
IgorSwat 0ea6d9f
Remove warnings
IgorSwat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/react-native-executorch/common/runner/arange_util.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #include "arange_util.h" | ||
|
|
||
| namespace torch::executor::native { | ||
| #define ET_ARANGE_IMPL(ctx, start, numel, step, out, op_name) \ | ||
| ET_SWITCH_REALHBF16_TYPES(out.scalar_type(), ctx, op_name, CTYPE, [&]() { \ | ||
| auto out_data = out.mutable_data_ptr<CTYPE>(); \ | ||
| for (executorch::aten::SizesType i = 0; i < numel; ++i) { \ | ||
| out_data[i] = static_cast<CTYPE>(start + i * step); \ | ||
| } \ | ||
| }) | ||
|
|
||
| executorch::aten::SizesType compute_arange_out_size(double start, double end, | ||
| double step) { | ||
| executorch::aten::SizesType numel = | ||
| static_cast<executorch::aten::SizesType>(std::ceil((end - start) / step)); | ||
|
|
||
| ET_CHECK_MSG(numel >= 0, | ||
| "numel should be non-negative, but got (%" PRId64 | ||
| "). start (%f), end (%f), step (%f)", | ||
| static_cast<int64_t>(numel), start, end, step); | ||
| return numel; | ||
| } | ||
|
|
||
| void arange_out_impl(KernelRuntimeContext &ctx, double start, double end, | ||
| double step, Tensor &out) { | ||
| (void)ctx; | ||
| executorch::aten::SizesType numel = compute_arange_out_size(start, end, step); | ||
| ET_ARANGE_IMPL(ctx, start, numel, step, out, "arange.start_out"); | ||
| } | ||
|
|
||
| void arange_out_impl(KernelRuntimeContext &ctx, double end, Tensor &out) { | ||
| (void)ctx; | ||
| ET_ARANGE_IMPL(ctx, 0.0, end, 1.0, out, "arange.out"); | ||
| } | ||
|
|
||
| } // namespace torch::executor::native |
37 changes: 37 additions & 0 deletions
37
packages/react-native-executorch/common/runner/arange_util.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "kernel_includes.h" | ||
|
|
||
| namespace torch::executor::native { | ||
|
|
||
| executorch::aten::SizesType compute_arange_out_size(double start, double end, | ||
| double step); | ||
|
|
||
| inline executorch::aten::SizesType compute_arange_out_size(double end) { | ||
| return compute_arange_out_size(0.0, end, 1.0); | ||
| } | ||
|
|
||
| void arange_out_impl(KernelRuntimeContext &ctx, double start, double end, | ||
| double step, Tensor &out); | ||
|
|
||
| void arange_out_impl(KernelRuntimeContext &ctx, double end, Tensor &out); | ||
|
|
||
| inline void arange_out_impl(double start, double end, double step, | ||
| Tensor &out) { | ||
| KernelRuntimeContext ctx; | ||
| arange_out_impl(ctx, start, end, step, out); | ||
| } | ||
|
|
||
| inline void arange_out_impl(double end, Tensor &out) { | ||
| KernelRuntimeContext ctx; | ||
| arange_out_impl(ctx, 0.0, end, 1.0, out); | ||
| } | ||
| } // namespace torch::executor::native |
28 changes: 28 additions & 0 deletions
28
packages/react-native-executorch/common/runner/constants.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
| #pragma once | ||
| // constants for LLM runtime | ||
| namespace executorch::extension::llm { | ||
|
|
||
| // Runtime metadata key constants | ||
| inline constexpr auto kEnableDynamicShape = "enable_dynamic_shape"; | ||
| inline constexpr auto kBosId = "get_bos_id"; | ||
| inline constexpr auto kEosIds = "get_eos_ids"; | ||
| inline constexpr auto kMaxSeqLen = "get_max_seq_len"; | ||
| inline constexpr auto kMaxContextLen = "get_max_context_len"; | ||
| inline constexpr auto kVocabSize = "get_vocab_size"; | ||
| inline constexpr auto kUseKVCache = "use_kv_cache"; | ||
| inline constexpr auto kUseSDPAWithKVCache = "use_sdpa_with_kv_cache"; | ||
|
|
||
| // Multimodal method name conventions | ||
| inline constexpr auto kVisionEncoderMethod = "vision_encoder"; | ||
| inline constexpr auto kAudioEncoderMethod = "audio_encoder"; | ||
| inline constexpr auto kTokenEmbeddingMethod = "token_embedding"; | ||
| inline constexpr auto kTextModelMethod = "text_decoder"; | ||
|
|
||
| } // namespace executorch::extension::llm |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is removed, is it not needed anymore for Gemma?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExecuTorch 1.0 introduces its own implementation of this mechanism with the new TextDecoderRunner and specifically
populate_start_pos_or_cache_position()function, so our extra code is no longer needed.