Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Conversation

@zhangguanheng66
Copy link
Contributor

@zhangguanheng66 zhangguanheng66 commented Nov 22, 2020

Add pybind11 pickle support for

  • experimental.vocab
  • experimental.vectors
  • experimental.basic_english_normalize

No need to call to_ivalue before saving.

@codecov
Copy link

codecov bot commented Nov 23, 2020

Codecov Report

Merging #1085 (54deffc) into master (d6d7f20) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1085   +/-   ##
=======================================
  Coverage   77.54%   77.54%           
=======================================
  Files          45       45           
  Lines        3086     3086           
=======================================
  Hits         2393     2393           
  Misses        693      693           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6d7f20...54deffc. Read the comment docs.

@zhangguanheng66 zhangguanheng66 changed the title [WIP] pybind11 pickle sentencepiece [WIP] pybind11 pickle support Nov 23, 2020
@zhangguanheng66 zhangguanheng66 changed the title [WIP] pybind11 pickle support pybind11 pickle support for experimental vocab and vectors Nov 24, 2020
.def("get_stoi", &Vocab::get_stoi)
.def("get_itos", &Vocab::get_itos);
.def("get_itos", &Vocab::get_itos)
.def(py::pickle(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can use the existing _set_vocab_states etc. functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to def_pickle func of torchbind, I tried _set_vectors_states and _get_vectors_from_states in py::pickle func of pybind11. However, the intrusive_ptr holder used by _set_vectors_states and _get_vectors_from_states are not supported in pybind11 pickle mechanism.

 error: static assertion failed: pybind11::init(): init function must return a compatible pointer, holder, or value

Copy link
Contributor

@cpuhrsch cpuhrsch Dec 1, 2020

Choose a reason for hiding this comment

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

I think you could change

_set_vectors_states(const c10::intrusive_ptr<Vectors> &self)

to

_set_vectors_states(const Vectors &self)

and then change the callsite of _set_vectors_states(self) to _set_vectors_states(*self).

You could even use move semantics

@zhangguanheng66 zhangguanheng66 changed the title pybind11 pickle support for experimental vocab and vectors pybind11 pickle support for experimental vocab, vectors, basic_english_normalize Dec 4, 2020
@zhangguanheng66 zhangguanheng66 changed the title pybind11 pickle support for experimental vocab, vectors, basic_english_normalize pybind11 pickle support for experimental vocab, vectors, regex_tokenizer Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants