-
Notifications
You must be signed in to change notification settings - Fork 806
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
Decode stream python #1678
Decode stream python #1678
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
Sounds good, I am a bit curious about the rational behind not using / creating a rust DecodeStream
/// | ||
#[pyclass(module = "tokenizers.decoders", name = "DecodeStream")] | ||
#[derive(Clone)] | ||
pub struct PyDecodeStream { |
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.
intersting, so we don't use the rust DecodeStream
object. I am guessing it's for ownership reasons? Otherwise we needs to wrap the PyDecodeStream {stream: DecodeStream}
with arc?
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.
Arc doesn't save us. The issue is with the borrow of the tokenizer's lifetime.
You can technically reborrow in every call in rust too, it's just not very "rusty".
For Python, we need to get access to the tokenizer on every call, and cloning into an Arc feels super wasteful (and breaks every update you might do on the tokenizer afterwards).
This seems innocuous enough since currently users have to hold already a reference to the tokenizer anyway.
} | ||
} | ||
|
||
/// Internal function exposed only to bypass python limitations |
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.
what were the limitations?
Lifetimes cannot cross the boundary. |
Different API because Python cannot handle lifetimes properly.
e16eaac
to
70c4f6b
Compare
Follow up of #1677