diff --git a/docs/data_utils.html b/docs/data_utils.html index a69976b..67685cb 100644 --- a/docs/data_utils.html +++ b/docs/data_utils.html @@ -39,6 +39,9 @@

Module mimir.data_utils

class Data: + """ + Data class to load and cache datasets. + """ def __init__(self, name, config: ExperimentConfig, presampled: str = None, @@ -65,6 +68,9 @@

Module mimir.data_utils

model: str = "bert", in_place_swap: bool = False, ): + """ + Load neighbors from cache (local or from HF) + """ data_split = "train" if train else "test" data_split += "_neighbors" filename = self._get_name_to_save() + "_neighbors_{}_{}".format( @@ -92,6 +98,9 @@

Module mimir.data_utils

model: str = "bert", in_place_swap: bool = False, ): + """ + Dump neighbors to cache local cache. + """ data_split = "train" if train else "test" data_split += "_neighbors" filename = self._get_name_to_save() + "_neighbors_{}_{}".format( @@ -338,6 +347,9 @@

Module mimir.data_utils

def sourcename_process(x: str): + """ + Helper function to process source name. + """ return x.replace(" ", "_").replace("-", "_").lower() @@ -398,12 +410,15 @@

Functions

def sourcename_process(x: str)
-
+

Helper function to process source name.

Expand source code
def sourcename_process(x: str):
+    """
+        Helper function to process source name.
+    """
     return x.replace(" ", "_").replace("-", "_").lower()
@@ -476,12 +491,15 @@

Classes

(name, config: ExperimentConfig, presampled: str = None, name_key_mapping: dict = {'the_pile': 'text', 'xsum': 'document'})
-
+

Data class to load and cache datasets.

Expand source code
class Data:
+    """
+    Data class to load and cache datasets.
+    """
     def __init__(self, name,
                  config: ExperimentConfig,
                  presampled: str = None,
@@ -508,6 +526,9 @@ 

Classes

model: str = "bert", in_place_swap: bool = False, ): + """ + Load neighbors from cache (local or from HF) + """ data_split = "train" if train else "test" data_split += "_neighbors" filename = self._get_name_to_save() + "_neighbors_{}_{}".format( @@ -535,6 +556,9 @@

Classes

model: str = "bert", in_place_swap: bool = False, ): + """ + Dump neighbors to cache local cache. + """ data_split = "train" if train else "test" data_split += "_neighbors" filename = self._get_name_to_save() + "_neighbors_{}_{}".format( @@ -739,7 +763,7 @@

Methods

def dump_neighbors(self, data, train: bool, num_neighbors: int, model: str = 'bert', in_place_swap: bool = False)
-
+

Dump neighbors to cache local cache.

Expand source code @@ -752,6 +776,9 @@

Methods

model: str = "bert", in_place_swap: bool = False, ): + """ + Dump neighbors to cache local cache. + """ data_split = "train" if train else "test" data_split += "_neighbors" filename = self._get_name_to_save() + "_neighbors_{}_{}".format( @@ -967,7 +994,7 @@

Methods

def load_neighbors(self, train: bool, num_neighbors: int, model: str = 'bert', in_place_swap: bool = False)
-
+

Load neighbors from cache (local or from HF)

Expand source code @@ -979,6 +1006,9 @@

Methods

model: str = "bert", in_place_swap: bool = False, ): + """ + Load neighbors from cache (local or from HF) + """ data_split = "train" if train else "test" data_split += "_neighbors" filename = self._get_name_to_save() + "_neighbors_{}_{}".format( diff --git a/docs/models.html b/docs/models.html index 9c5fe76..c22fc8b 100644 --- a/docs/models.html +++ b/docs/models.html @@ -248,10 +248,16 @@

Module mimir.models

self.load_model_properties() def load(self): + """ + Load reference model noto GPU(s) + """ if "llama" not in self.name and "alpaca" not in self.name: super().load() def unload(self): + """ + Unload reference model from GPU(s) + """ if "llama" not in self.name and "alpaca" not in self.name: super().unload() @@ -398,19 +404,6 @@

Module mimir.models

del label_batch del attention_mask return losses #np.mean(losses) - - @torch.no_grad() - def get_min_k_prob(self, text: str, tokens=None, probs=None, k=.2, window=1, stride=1): - all_prob = probs if probs is not None else self.get_probabilities(text, tokens=tokens) - # iterate through probabilities by ngram defined by window size at given stride - ngram_probs = [] - for i in range(0, len(all_prob) - window + 1, stride): - ngram_prob = all_prob[i:i+window] - ngram_probs.append(np.mean(ngram_prob)) - min_k_probs = sorted(ngram_probs)[:int(len(ngram_probs) * k)] - - return -np.mean(min_k_probs) - def sample_from_model(self, texts: List[str], **kwargs): """ @@ -464,11 +457,6 @@

Module mimir.models

logits = self.model(**tokenized).logits[:,:-1] neg_entropy = F.softmax(logits, dim=-1) * F.log_softmax(logits, dim=-1) return -neg_entropy.sum(-1).mean().item() - - @torch.no_grad() - def get_zlib_entropy(self, text: str, tokens=None, probs=None): - zlib_entropy = len(zlib.compress(bytes(text, 'utf-8'))) - return self.get_ll(text, tokens=tokens, probs=probs) / zlib_entropy @torch.no_grad() def get_max_norm(self, text: str, context_len=None, tk_freq_map=None): @@ -525,6 +513,9 @@

Module mimir.models

@property def api_calls(self): + """ + Get the number of tokens used in API calls + """ return self.API_TOKEN_COUNTER @torch.no_grad() @@ -763,19 +754,6 @@

Classes

del label_batch del attention_mask return losses #np.mean(losses) - - @torch.no_grad() - def get_min_k_prob(self, text: str, tokens=None, probs=None, k=.2, window=1, stride=1): - all_prob = probs if probs is not None else self.get_probabilities(text, tokens=tokens) - # iterate through probabilities by ngram defined by window size at given stride - ngram_probs = [] - for i in range(0, len(all_prob) - window + 1, stride): - ngram_prob = all_prob[i:i+window] - ngram_probs.append(np.mean(ngram_prob)) - min_k_probs = sorted(ngram_probs)[:int(len(ngram_probs) * k)] - - return -np.mean(min_k_probs) - def sample_from_model(self, texts: List[str], **kwargs): """ @@ -829,11 +807,6 @@

Classes

logits = self.model(**tokenized).logits[:,:-1] neg_entropy = F.softmax(logits, dim=-1) * F.log_softmax(logits, dim=-1) return -neg_entropy.sum(-1).mean().item() - - @torch.no_grad() - def get_zlib_entropy(self, text: str, tokens=None, probs=None): - zlib_entropy = len(zlib.compress(bytes(text, 'utf-8'))) - return self.get_ll(text, tokens=tokens, probs=probs) / zlib_entropy @torch.no_grad() def get_max_norm(self, text: str, context_len=None, tk_freq_map=None): @@ -1049,28 +1022,6 @@

Methods

return -np.mean(all_prob)
-
-def get_min_k_prob(self, text: str, tokens=None, probs=None, k=0.2, window=1, stride=1) -
-
-
-
- -Expand source code - -
@torch.no_grad()
-def get_min_k_prob(self, text: str, tokens=None, probs=None, k=.2, window=1, stride=1):
-    all_prob = probs if probs is not None else self.get_probabilities(text, tokens=tokens)
-    # iterate through probabilities by ngram defined by window size at given stride
-    ngram_probs = []
-    for i in range(0, len(all_prob) - window + 1, stride):
-        ngram_prob = all_prob[i:i+window]
-        ngram_probs.append(np.mean(ngram_prob))
-    min_k_probs = sorted(ngram_probs)[:int(len(ngram_probs) * k)]
-
-    return -np.mean(min_k_probs)
-
-
def get_rank(self, text: str, log: bool = False)
@@ -1129,21 +1080,6 @@

Methods

return lls - lls_ref -
-def get_zlib_entropy(self, text: str, tokens=None, probs=None) -
-
-
-
- -Expand source code - -
@torch.no_grad()
-def get_zlib_entropy(self, text: str, tokens=None, probs=None):
-    zlib_entropy = len(zlib.compress(bytes(text, 'utf-8')))
-    return self.get_ll(text, tokens=tokens, probs=probs) / zlib_entropy
-
-
def sample_from_model(self, texts: List[str], **kwargs)
@@ -1710,6 +1646,9 @@

Methods

@property def api_calls(self): + """ + Get the number of tokens used in API calls + """ return self.API_TOKEN_COUNTER @torch.no_grad() @@ -1829,13 +1768,16 @@

Instance variables

var api_calls
-
+

Get the number of tokens used in API calls

Expand source code
@property
 def api_calls(self):
+    """
+        Get the number of tokens used in API calls
+    """
     return self.API_TOKEN_COUNTER
@@ -2009,10 +1951,16 @@

Inherited members

self.load_model_properties() def load(self): + """ + Load reference model noto GPU(s) + """ if "llama" not in self.name and "alpaca" not in self.name: super().load() def unload(self): + """ + Unload reference model from GPU(s) + """ if "llama" not in self.name and "alpaca" not in self.name: super().unload() @@ -2036,6 +1984,43 @@

Class variables

+

Methods

+
+
+def load(self) +
+
+

Load reference model noto GPU(s)

+
+ +Expand source code + +
def load(self):
+    """
+    Load reference model noto GPU(s)
+    """
+    if "llama" not in self.name and "alpaca" not in self.name:
+        super().load()
+
+
+
+def unload(self) +
+
+

Unload reference model from GPU(s)

+
+ +Expand source code + +
def unload(self):
+    """
+    Unload reference model from GPU(s)
+    """
+    if "llama" not in self.name and "alpaca" not in self.name:
+        super().unload()
+
+
+

Inherited members

@@ -2076,10 +2059,8 @@

get_entropy
  • get_lls
  • get_max_norm
  • -
  • get_min_k_prob
  • get_rank
  • get_ref
  • -
  • get_zlib_entropy
  • sample_from_model
  • training
  • @@ -2124,7 +2105,9 @@

  • call_super_init
  • dump_patches
  • +
  • load
  • training
  • +
  • unload
  • diff --git a/docs/utils.html b/docs/utils.html index fc83948..652a515 100644 --- a/docs/utils.html +++ b/docs/utils.html @@ -41,6 +41,9 @@

    Module mimir.utils

    def fix_seed(seed: int = 0): + """ + Fix seed for reproducibility. + """ ch.manual_seed(seed) np.random.seed(seed) random.seed(seed) @@ -79,12 +82,15 @@

    Functions

    def fix_seed(seed: int = 0)
    -
    +

    Fix seed for reproducibility.

    Expand source code
    def fix_seed(seed: int = 0):
    +    """
    +    Fix seed for reproducibility.
    +    """
         ch.manual_seed(seed)
         np.random.seed(seed)
         random.seed(seed)