MCPcopy
hub / github.com/Turing-Project/WriteGPT / Statistics

Class Statistics

LanguageNetwork/BERT/models/stats.py:10–120  ·  view source on GitHub ↗

Accumulator for loss statistics. Currently calculates: * accuracy * perplexity * elapsed time

Source from the content-addressed store, hash-verified

8
9
10class Statistics(object):
11 """
12 Accumulator for loss statistics.
13 Currently calculates:
14
15 * accuracy
16 * perplexity
17 * elapsed time
18 """
19
20 def __init__(self, loss=0, n_docs=0, n_correct=0):
21 self.loss = loss
22 self.n_docs = n_docs
23 self.start_time = time.time()
24
25 @staticmethod
26 def all_gather_stats(stat, max_size=4096):
27 """
28 Gather a `Statistics` object accross multiple process/nodes
29
30 Args:
31 stat(:obj:Statistics): the statistics object to gather
32 accross all processes/nodes
33 max_size(int): max buffer size to use
34
35 Returns:
36 `Statistics`, the update stats object
37 """
38 stats = Statistics.all_gather_stats_list([stat], max_size=max_size)
39 return stats[0]
40
41 @staticmethod
42 def all_gather_stats_list(stat_list, max_size=4096):
43 """
44 Gather a `Statistics` list accross all processes/nodes
45
46 Args:
47 stat_list(list([`Statistics`])): list of statistics objects to
48 gather accross all processes/nodes
49 max_size(int): max buffer size to use
50
51 Returns:
52 our_stats(list([`Statistics`])): list of updated stats
53 """
54 from torch.distributed import get_rank
55 from distributed import all_gather_list
56
57 # Get a list of world_size lists with len(stat_list) Statistics objects
58 all_stats = all_gather_list(stat_list, max_size=max_size)
59
60 our_rank = get_rank()
61 our_stats = all_stats[our_rank]
62 for other_rank, stats in enumerate(all_stats):
63 if other_rank == our_rank:
64 continue
65 for i, stat in enumerate(stats):
66 our_stats[i].update(stat, update_n_src_words=True)
67 return our_stats

Callers 7

report_trainingMethod · 0.90
_report_trainingMethod · 0.90
trainMethod · 0.90
validateMethod · 0.90
testMethod · 0.90
predictMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected