Skip to content

Support Qwen3 (str.startswith() and [::-1]) #66

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 9 commits into from
May 15, 2025

Conversation

taha-yassine
Copy link
Contributor

@taha-yassine taha-yassine commented Apr 29, 2025

This PR:

  • implements the missing .startswith()
  • implements step=-1 in slice
  • adds Qwen3 template

Closes #64
Addresses ggml-org/llama.cpp#13178

@taha-yassine taha-yassine changed the title Add str.startswith() Support Qwen3 (str.startswith() and [::-1]) Apr 30, 2025
@taha-yassine
Copy link
Contributor Author

I added support for step=-1 in slice since ggml-org/llama.cpp#13181 was closed.

grf53 added a commit to grf53/minja that referenced this pull request May 6, 2025
@grf53 grf53 mentioned this pull request May 8, 2025
Copy link
Collaborator

@ochafik ochafik left a comment

Choose a reason for hiding this comment

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

This is awesome, thanks @taha-yassine!!!

@@ -1220,19 +1220,54 @@ class SubscriptExpr : public Expression {
if (!index) throw std::runtime_error("SubscriptExpr.index is null");
auto target_value = base->evaluate(context);
if (auto slice = dynamic_cast<SliceExpr*>(index.get())) {
auto start = slice->start ? slice->start->evaluate(context).get<int64_t>() : 0;
auto end = slice->end ? slice->end->evaluate(context).get<int64_t>() : (int64_t) target_value.size();
bool reverse = slice->step && slice->step->evaluate(context).get<int64_t>() == -1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: for readability I'd maybe first extract step (default to 1), then do the reverse + explosion if step not in (1,-1)

int64_t start = slice->start ? slice->start->evaluate(context).get<int64_t>() : (reverse ? target_value.size() - 1 : 0);
int64_t end = slice->end ? slice->end->evaluate(context).get<int64_t>() : (reverse ? -1 : target_value.size());

size_t len = target_value.size();
Copy link
Collaborator

Choose a reason for hiding this comment

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

move this one up to use it instead of target_value.size() calls

@ochafik
Copy link
Collaborator

ochafik commented May 15, 2025

@taha-yassine I've taken the liberty to simplify the code a bit (now supports any step != 0) + test strings, ptal (edit: ) merging now :-)

@ochafik ochafik self-requested a review May 15, 2025 10:40
@ochafik ochafik merged commit 17a767a into google:main May 15, 2025
3 of 11 checks passed
@taha-yassine
Copy link
Contributor Author

@taha-yassine I've taken the liberty to simplify the code a bit (now supports any step != 0) + test strings, ptal (edit: ) merging now :-)

Awesome thanks!

Related to the out-of-bounds issue I mentioned, it seems that your code doesn't handle that case? I wrote a little test to verify and it doesn't pass.

EXPECT_EQ(
    "[0, 1, 2, 3][0, 1, 2, 3][]",
    render("{% set x = [0, 1, 2, 3] %}{{ x[-10:] }}{{ x[:10] }}{{ x[10:20] }}", {}, {}));

Or maybe the complexity it adds isn't worth it?

ochafik added a commit to ggml-org/llama.cpp that referenced this pull request May 15, 2025
* minja: sync google/minja@f06140f

- google/minja#67 (@grf53)
- google/minja#66 (@taha-yassine)
- google/minja#63 (@grf53)
- google/minja#58

---------

Co-authored-by: ochafik <ochafik@google.com>
Erick-0923 pushed a commit to Erick-0923/llama.cpp that referenced this pull request May 30, 2025
* minja: sync google/minja@f06140f

- google/minja#67 (@grf53)
- google/minja#66 (@taha-yassine)
- google/minja#63 (@grf53)
- google/minja#58

---------

Co-authored-by: ochafik <ochafik@google.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.

Support Qwen3
2 participants