MCPcopy Create free account
hub / github.com/Standard-Intelligence/hertz-dev / get_code_utilization

Function get_code_utilization

ioblocks.py:109–123  ·  view source on GitHub ↗
(codes, codebook_size, get_global=False)

Source from the content-addressed store, hash-verified

107 return ceil(num / mult) * mult
108
109def get_code_utilization(codes, codebook_size, get_global=False):
110 if get_global and dist.is_initialized():
111 world_size = dist.get_world_size()
112 else:
113 world_size = 1
114
115 if world_size > 1:
116 gathered_tokens = [T.zeros_like(codes) for _ in range(world_size)]
117 dist.all_gather(gathered_tokens, codes)
118 gathered_tokens = T.cat(gathered_tokens, dim=0)
119 else:
120 gathered_tokens = codes
121 unique_tokens = len(T.unique(gathered_tokens))
122 code_utilization = unique_tokens / min(gathered_tokens.numel(), codebook_size)
123 return code_utilization
124
125# tensor helpers
126

Callers 1

latent_metricMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected