Skip to content

Commit 581a3a4

Browse files
abhinavarorahenryhu6r-barnes
authored
Sync fbsync branch to main (#2210)
* Move tensor to CPU before converting to string for unpickle Summary: The loaded tensor could be on CUDA, whose data cannot to converted to a std::string. This change moves tensor to CPU first. Then data can be converted. Reviewed By: mortzur Differential Revision: D48057806 fbshipit-source-id: ad495bb2e84f9aab5120d5462d4d1c381719d014 * Del `(object)` from 10 inc pytorch/tensorboardX/tensorboardX/record_writer.py Summary: Python3 makes the use of `(object)` in class inheritance unnecessary. Let's modernize our code by eliminating this. Reviewed By: meyering Differential Revision: D48958009 fbshipit-source-id: aa42e55a827d83aadf1b10b2de79317c3761ab7a --------- Co-authored-by: Henry Hu <[email protected]> Co-authored-by: Richard Barnes <[email protected]>
1 parent 45e4b8c commit 581a3a4

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

torchtext/csrc/register_torchbindings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ TORCH_LIBRARY_FRAGMENT(torchtext, m) {
6767
},
6868
// __setstate__
6969
[](torch::Tensor state) -> c10::intrusive_ptr<SentencePiece> {
70+
state = state.to(at::kCPU);
7071
auto* data = static_cast<char*>(state.data_ptr());
7172
auto numel = state.size(0);
7273
return c10::make_intrusive<SentencePiece>(std::string(data, numel));

torchtext/data/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _get_ngrams(n):
228228
yield " ".join(x)
229229

230230

231-
class RandomShuffler(object):
231+
class RandomShuffler:
232232
"""Use random functions while keeping track of the random state to make it
233233
reproducible and deterministic."""
234234

torchtext/vocab/vectors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _infer_shape(f):
3131
return num_lines, vector_dim
3232

3333

34-
class Vectors(object):
34+
class Vectors:
3535
def __init__(self, name, cache=None, url=None, unk_init=None, max_vectors=None) -> None:
3636
"""
3737
Args:

0 commit comments

Comments
 (0)