Skip to content
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

Close open files to suppress ResourceWarning #11240

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/legacy/seq2seq/run_distributed_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def run_generate():
save_json(preds, save_path)
return
tgt_file = Path(args.data_dir).joinpath(args.type_path + ".target")
labels = [x.rstrip() for x in open(tgt_file).readlines()][: len(preds)]
with open(tgt_file) as f:
labels = [x.rstrip() for x in f.readlines()][: len(preds)]

# Calculate metrics, save metrics, and save _generations.txt
calc_bleu = "translation" in args.task
Expand Down
3 changes: 2 additions & 1 deletion examples/research_projects/seq2seq-distillation/run_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def run_generate(verbose=True):
parsed_args = parse_numeric_n_bool_cl_kwargs(rest)
if parsed_args and verbose:
print(f"parsed the following generate kwargs: {parsed_args}")
examples = [" " + x.rstrip() if "t5" in args.model_name else x.rstrip() for x in open(args.input_path).readlines()]
with open(args.input_path) as f:
examples = [" " + x.rstrip() if "t5" in args.model_name else x.rstrip() for x in f.readlines()]
if args.n_obs > 0:
examples = examples[: args.n_obs]
Path(args.save_path).parent.mkdir(exist_ok=True)
Expand Down
3 changes: 2 additions & 1 deletion src/transformers/convert_slow_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ def __init__(self, *args):
from .utils import sentencepiece_model_pb2 as model_pb2

m = model_pb2.ModelProto()
m.ParseFromString(open(self.original_tokenizer.vocab_file, "rb").read())
with open(self.original_tokenizer.vocab_file, "rb") as f:
m.ParseFromString(f.read())
self.proto = m

def vocab(self, proto):
Expand Down