-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
I added support for step=-1 in slice since ggml-org/llama.cpp#13181 was closed. |
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.
This is awesome, thanks @taha-yassine!!!
include/minja/minja.hpp
Outdated
@@ -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; |
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.
nit: for readability I'd maybe first extract step (default to 1), then do the reverse + explosion if step not in (1,-1)
include/minja/minja.hpp
Outdated
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(); |
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.
move this one up to use it instead of target_value.size() calls
@taha-yassine I've taken the liberty to simplify the code a bit (now supports any step != 0) + test strings, |
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? |
* 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>
* 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>
This PR:
.startswith()
Closes #64
Addresses ggml-org/llama.cpp#13178