log

verta.runtime.log(key: str, value: Any) None

Updates current logging dict with provided key and value.

For use within the scope of a model’s predict() method to collect logs. All logs passed to this function are aggregated into a single dictionary within the context of one prediction, which is processed into storage after the prediction result is returned, to minimize added latency.

Note

Existing keys cannot be overwritten. Multithreading of calls to log() within a model’s predict() method is not currently supported.

Parameters:
  • key (str) – String value to use as data label (key) in logs, with a limit of 100 characters or less.

  • value (Any) – Any JSON serializable value you wish to include in the logs.

Returns:

None

Raises:
  • TypeError – If validate was set to True on the active context, and value is not a JSON-serializable type.

  • ValueError – If key provided contains non-alphanumeric characters (Dashes - and underscores _ are permitted), or the key already exists and the existing log cannot be overwritten.

  • RuntimeError – If this function is called outside the scope of any instance of context.

Examples

 from verta import runtime

 # Sample model code:
 class MyModel(VertaModelBase):
     def __init__(self, artifacts):
         pass

     @verify_io
     def predict(self, x):
         embeddings = self.get_embeddings(x)
         return self.nn(embeddings)

     def get_embeddings(self, x):
         embedding = self.embedding[x]
         runtime.log("embedding", embedding)
         return embedding