Skip to content

Commit fe6c2ed

Browse files
Myle Ottfacebook-github-bot
authored andcommitted
Deprecate --fast-stat-sync and replace with Criterion.logging_outputs_can_be_summed
Summary: Pull Request resolved: fairinternal/fairseq-py#980 Differential Revision: D19351116 Pulled By: myleott fbshipit-source-id: a67b10637f53a80c37b0ce90eb27ced9709871db
1 parent c9a7c06 commit fe6c2ed

12 files changed

+167
-70
lines changed

fairseq/criterions/adaptive_loss.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,12 @@ def aggregate_logging_outputs(logging_outputs):
9090
if sample_size != ntokens:
9191
agg_output['nll_loss'] = loss_sum / ntokens / math.log(2) if ntokens > 0 else 0.
9292
return agg_output
93+
94+
@staticmethod
95+
def logging_outputs_can_be_summed() -> bool:
96+
"""
97+
Whether the logging outputs returned by `forward` can be summed
98+
across workers prior to calling `aggregate_logging_outputs`.
99+
Setting this to True will improves distributed training speed.
100+
"""
101+
return True

fairseq/criterions/cross_entropy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,12 @@ def aggregate_logging_outputs(logging_outputs):
6565
if sample_size != ntokens:
6666
agg_output['nll_loss'] = loss_sum / ntokens / math.log(2)
6767
return agg_output
68+
69+
@staticmethod
70+
def logging_outputs_can_be_summed() -> bool:
71+
"""
72+
Whether the logging outputs returned by `forward` can be summed
73+
across workers prior to calling `aggregate_logging_outputs`.
74+
Setting this to True will improves distributed training speed.
75+
"""
76+
return True

fairseq/criterions/fairseq_criterion.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ def forward(self, model, sample, reduce=True):
3737
def aggregate_logging_outputs(logging_outputs):
3838
"""Aggregate logging outputs from data parallel training."""
3939
raise NotImplementedError
40+
41+
@staticmethod
42+
def logging_outputs_can_be_summed() -> bool:
43+
"""
44+
Whether the logging outputs returned by `forward` can be summed
45+
across workers prior to calling `aggregate_logging_outputs`.
46+
Setting this to True will improves distributed training speed.
47+
"""
48+
return False

fairseq/criterions/label_smoothed_cross_entropy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,12 @@ def aggregate_logging_outputs(logging_outputs):
8888
'nsentences': nsentences,
8989
'sample_size': sample_size,
9090
}
91+
92+
@staticmethod
93+
def logging_outputs_can_be_summed() -> bool:
94+
"""
95+
Whether the logging outputs returned by `forward` can be summed
96+
across workers prior to calling `aggregate_logging_outputs`.
97+
Setting this to True will improves distributed training speed.
98+
"""
99+
return True

fairseq/criterions/label_smoothed_cross_entropy_with_alignment.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,12 @@ def aggregate_logging_outputs(logging_outputs):
8888
'nsentences': nsentences,
8989
'sample_size': sample_size,
9090
}
91+
92+
@staticmethod
93+
def logging_outputs_can_be_summed() -> bool:
94+
"""
95+
Whether the logging outputs returned by `forward` can be summed
96+
across workers prior to calling `aggregate_logging_outputs`.
97+
Setting this to True will improves distributed training speed.
98+
"""
99+
return True

fairseq/criterions/legacy_masked_lm.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,12 @@ def aggregate_logging_outputs(logging_outputs):
145145
'sample_size': sample_size,
146146
}
147147
return agg_output
148+
149+
@staticmethod
150+
def logging_outputs_can_be_summed() -> bool:
151+
"""
152+
Whether the logging outputs returned by `forward` can be summed
153+
across workers prior to calling `aggregate_logging_outputs`.
154+
Setting this to True will improves distributed training speed.
155+
"""
156+
return True

fairseq/criterions/masked_lm.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ def aggregate_logging_outputs(logging_outputs):
7979
'sample_size': sample_size,
8080
}
8181
return agg_output
82+
83+
@staticmethod
84+
def logging_outputs_can_be_summed() -> bool:
85+
"""
86+
Whether the logging outputs returned by `forward` can be summed
87+
across workers prior to calling `aggregate_logging_outputs`.
88+
Setting this to True will improves distributed training speed.
89+
"""
90+
return True

fairseq/criterions/nat_loss.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,12 @@ def aggregate_logging_outputs(logging_outputs):
167167
)
168168

169169
return results
170+
171+
@staticmethod
172+
def logging_outputs_can_be_summed() -> bool:
173+
"""
174+
Whether the logging outputs returned by `forward` can be summed
175+
across workers prior to calling `aggregate_logging_outputs`.
176+
Setting this to True will improves distributed training speed.
177+
"""
178+
return True

fairseq/criterions/sentence_prediction.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,12 @@ def aggregate_logging_outputs(logging_outputs):
9696
if sample_size != ntokens:
9797
agg_output['nll_loss'] = loss_sum / ntokens / math.log(2)
9898
return agg_output
99+
100+
@staticmethod
101+
def logging_outputs_can_be_summed() -> bool:
102+
"""
103+
Whether the logging outputs returned by `forward` can be summed
104+
across workers prior to calling `aggregate_logging_outputs`.
105+
Setting this to True will improves distributed training speed.
106+
"""
107+
return True

fairseq/criterions/sentence_ranking.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,12 @@ def aggregate_logging_outputs(logging_outputs):
115115
if sample_size != ntokens:
116116
agg_output['nll_loss'] = loss_sum / ntokens / math.log(2)
117117
return agg_output
118+
119+
@staticmethod
120+
def logging_outputs_can_be_summed() -> bool:
121+
"""
122+
Whether the logging outputs returned by `forward` can be summed
123+
across workers prior to calling `aggregate_logging_outputs`.
124+
Setting this to True will improves distributed training speed.
125+
"""
126+
return True

0 commit comments

Comments
 (0)