Skip to content

Commit e77ffcd

Browse files
committed
Fix FutureWarning: functools.partial in Python 3.13
`FutureWarning: functools.partial will be a method descriptor in future Python versions; wrap it in staticmethod() if you want to preserve the old behavior`
1 parent dc9c6b2 commit e77ffcd

File tree

29 files changed

+121
-111
lines changed

29 files changed

+121
-111
lines changed

examples/asr/emformer_rnnt/librispeech/lightning.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,20 @@ def __init__(
7979
self.train_data_pipeline = torch.nn.Sequential(
8080
FunctionalModule(piecewise_linear_log),
8181
GlobalStatsNormalization(global_stats_path),
82-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
82+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
8383
torchaudio.transforms.FrequencyMasking(27),
8484
torchaudio.transforms.FrequencyMasking(27),
8585
torchaudio.transforms.TimeMasking(100, p=0.2),
8686
torchaudio.transforms.TimeMasking(100, p=0.2),
87-
FunctionalModule(partial(torch.nn.functional.pad, pad=(0, 4))),
88-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
87+
FunctionalModule(staticmethod(partial(torch.nn.functional.pad, pad=(0, 4)))),
88+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
8989
)
9090
self.valid_data_pipeline = torch.nn.Sequential(
9191
FunctionalModule(piecewise_linear_log),
9292
GlobalStatsNormalization(global_stats_path),
93-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
94-
FunctionalModule(partial(torch.nn.functional.pad, pad=(0, 4))),
95-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
93+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
94+
FunctionalModule(staticmethod(partial(torch.nn.functional.pad, pad=(0, 4)))),
95+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
9696
)
9797

9898
self.librispeech_path = librispeech_path

examples/asr/emformer_rnnt/mustc/lightning.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ def __init__(
5757
self.train_data_pipeline = torch.nn.Sequential(
5858
FunctionalModule(piecewise_linear_log),
5959
GlobalStatsNormalization(global_stats_path),
60-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
60+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
6161
torchaudio.transforms.FrequencyMasking(27),
6262
torchaudio.transforms.FrequencyMasking(27),
6363
torchaudio.transforms.TimeMasking(100, p=0.2),
6464
torchaudio.transforms.TimeMasking(100, p=0.2),
65-
FunctionalModule(partial(torch.nn.functional.pad, pad=(0, 4))),
66-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
65+
FunctionalModule(staticmethod(partial(torch.nn.functional.pad, pad=(0, 4)))),
66+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
6767
)
6868
self.valid_data_pipeline = torch.nn.Sequential(
6969
FunctionalModule(piecewise_linear_log),
7070
GlobalStatsNormalization(global_stats_path),
71-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
72-
FunctionalModule(partial(torch.nn.functional.pad, pad=(0, 4))),
73-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
71+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
72+
FunctionalModule(staticmethod(partial(torch.nn.functional.pad, pad=(0, 4)))),
73+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
7474
)
7575

7676
self.mustc_path = mustc_path

examples/asr/emformer_rnnt/pipeline_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ class Config:
2929

3030
_CONFIGS = {
3131
MODEL_TYPE_LIBRISPEECH: Config(
32-
partial(torchaudio.datasets.LIBRISPEECH, url="test-clean"),
32+
staticmethod(partial(torchaudio.datasets.LIBRISPEECH, url="test-clean")),
3333
EMFORMER_RNNT_BASE_LIBRISPEECH,
3434
),
3535
MODEL_TYPE_MUSTC: Config(
36-
partial(MUSTC, subset="tst-COMMON"),
36+
staticmethod(partial(MUSTC, subset="tst-COMMON")),
3737
EMFORMER_RNNT_BASE_MUSTC,
3838
),
3939
MODEL_TYPE_TEDLIUM3: Config(
40-
partial(torchaudio.datasets.TEDLIUM, release="release3", subset="test"),
40+
staticmethod(partial(torchaudio.datasets.TEDLIUM, release="release3", subset="test")),
4141
EMFORMER_RNNT_BASE_TEDLIUM3,
4242
),
4343
}

examples/asr/emformer_rnnt/tedlium3/lightning.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,20 @@ def __init__(
8787
self.train_data_pipeline = torch.nn.Sequential(
8888
FunctionalModule(piecewise_linear_log),
8989
GlobalStatsNormalization(global_stats_path),
90-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
90+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
9191
torchaudio.transforms.FrequencyMasking(27),
9292
torchaudio.transforms.FrequencyMasking(27),
9393
torchaudio.transforms.TimeMasking(100, p=0.2),
9494
torchaudio.transforms.TimeMasking(100, p=0.2),
95-
FunctionalModule(partial(torch.nn.functional.pad, pad=(0, 4))),
96-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
95+
FunctionalModule(staticmethod(partial(torch.nn.functional.pad, pad=(0, 4)))),
96+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
9797
)
9898
self.valid_data_pipeline = torch.nn.Sequential(
9999
FunctionalModule(piecewise_linear_log),
100100
GlobalStatsNormalization(global_stats_path),
101-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
102-
FunctionalModule(partial(torch.nn.functional.pad, pad=(0, 4))),
103-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
101+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
102+
FunctionalModule(staticmethod(partial(torch.nn.functional.pad, pad=(0, 4)))),
103+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
104104
)
105105

106106
self.tedlium_path = tedlium_path

examples/asr/librispeech_conformer_rnnt/transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ def __init__(self, global_stats_path: str, sp_model_path: str):
7171
self.train_data_pipeline = torch.nn.Sequential(
7272
FunctionalModule(_piecewise_linear_log),
7373
GlobalStatsNormalization(global_stats_path),
74-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
74+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
7575
torchaudio.transforms.FrequencyMasking(27),
7676
torchaudio.transforms.FrequencyMasking(27),
7777
torchaudio.transforms.TimeMasking(100, p=0.2),
7878
torchaudio.transforms.TimeMasking(100, p=0.2),
79-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
79+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
8080
)
8181

8282
def __call__(self, samples: List):

examples/asr/librispeech_conformer_rnnt_biasing/transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ def __init__(self, global_stats_path: str, sp_model_path: str, blist: List[str],
113113
self.train_data_pipeline = torch.nn.Sequential(
114114
FunctionalModule(_piecewise_linear_log),
115115
GlobalStatsNormalization(global_stats_path),
116-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
116+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
117117
torchaudio.transforms.FrequencyMasking(27),
118118
torchaudio.transforms.FrequencyMasking(27),
119119
torchaudio.transforms.TimeMasking(100, p=0.2),
120120
torchaudio.transforms.TimeMasking(100, p=0.2),
121-
FunctionalModule(partial(torch.transpose, dim0=1, dim1=2)),
121+
FunctionalModule(staticmethod(partial(torch.transpose, dim0=1, dim1=2))),
122122
)
123123
self.blist = blist
124124
self.droprate = droprate

examples/pipeline_tacotron2/inference.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,14 @@ def main(args):
253253
raise ValueError("Both --checkpoint-path and --checkpoint-name are specified, " "can only specify one.")
254254

255255
n_symbols = len(get_symbol_list(args.text_preprocessor))
256-
text_preprocessor = partial(
257-
text_to_sequence,
258-
symbol_list=args.text_preprocessor,
259-
phonemizer=args.phonemizer,
260-
checkpoint=args.phonemizer_checkpoint,
261-
cmudict_root=args.cmudict_root,
256+
text_preprocessor = staticmethod(
257+
partial(
258+
text_to_sequence,
259+
symbol_list=args.text_preprocessor,
260+
phonemizer=args.phonemizer,
261+
checkpoint=args.phonemizer_checkpoint,
262+
cmudict_root=args.cmudict_root,
263+
)
262264
)
263265

264266
if args.checkpoint_path is not None:

examples/pipeline_tacotron2/train.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,14 @@ def log_additional_info(writer, model, loader, epoch):
273273

274274

275275
def get_datasets(args):
276-
text_preprocessor = partial(
277-
text_to_sequence,
278-
symbol_list=args.text_preprocessor,
279-
phonemizer=args.phonemizer,
280-
checkpoint=args.phonemizer_checkpoint,
281-
cmudict_root=args.cmudict_root,
276+
text_preprocessor = staticmethod(
277+
partial(
278+
text_to_sequence,
279+
symbol_list=args.text_preprocessor,
280+
phonemizer=args.phonemizer,
281+
checkpoint=args.phonemizer_checkpoint,
282+
cmudict_root=args.cmudict_root,
283+
)
282284
)
283285

284286
transforms = torch.nn.Sequential(
@@ -391,7 +393,7 @@ def train(rank, world_size, args):
391393
"shuffle": False,
392394
"pin_memory": True,
393395
"drop_last": False,
394-
"collate_fn": partial(text_mel_collate_fn, n_frames_per_step=args.n_frames_per_step),
396+
"collate_fn": staticmethod(partial(text_mel_collate_fn, n_frames_per_step=args.n_frames_per_step)),
395397
}
396398

397399
train_loader = DataLoader(trainset, sampler=train_sampler, **loader_params)

examples/self_supervised_learning/train_hubert.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ def run_train(args):
115115
f"Found {args.model_name}."
116116
)
117117
model = getattr(torchaudio.models, args.model_name)()
118-
loss_fn = partial(
119-
hubert_loss,
120-
masked_weight=args.masked_weight,
121-
unmasked_weight=args.unmasked_weight,
122-
feature_weight=args.feature_weight,
118+
loss_fn = staticmethod(
119+
partial(
120+
hubert_loss,
121+
masked_weight=args.masked_weight,
122+
unmasked_weight=args.unmasked_weight,
123+
feature_weight=args.feature_weight,
124+
)
123125
)
124126
optimizer = torch.optim.AdamW(
125127
model.parameters(),

examples/source_separation/utils/dataset/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ def get_collate_fn(dataset_type, mode, sample_rate=None, duration=4):
8484
if mode == "train":
8585
if sample_rate is None:
8686
raise ValueError("sample_rate is not given.")
87-
return partial(collate_fn_wsj0mix_train, sample_rate=sample_rate, duration=duration)
88-
return partial(collate_fn_wsj0mix_test, sample_rate=sample_rate)
87+
return staticmethod(partial(collate_fn_wsj0mix_train, sample_rate=sample_rate, duration=duration))
88+
return staticmethod(partial(collate_fn_wsj0mix_test, sample_rate=sample_rate))
8989
raise ValueError(f"Unexpected dataset: {dataset_type}")

0 commit comments

Comments
 (0)