Class HfCheckpoint

java.lang.Object
ai.beestream.jitnn.nn.models.HfCheckpoint

public final class HfCheckpoint extends Object
A Hugging Face model directory: config.json and the weights in model.safetensors or in shards listed by model.safetensors.index.json. Weights are looked up with or without the architecture prefix (bert., transformer., model.), and old LayerNorm names (gamma, beta) are accepted for weight and bias. The model classes use it in their fromHuggingFace factories; it also serves custom models.
  • Method Details

    • open

      public static HfCheckpoint open(Path dir) throws IOException
      Opens a model directory.
      Throws:
      IOException
    • directory

      public Path directory()
      The directory the checkpoint was read from.
    • config

      public Map<?,?> config()
      The parsed config.json.
    • configInt

      public int configInt(String... keys)
      The first of keys present in the config, as an int; throws when none is.
    • configFloat

      public float configFloat(String key, float otherwise)
      Config value key as a float, or otherwise when absent.
    • configString

      public String configString(String key, String otherwise)
      Config value key as a string, or otherwise when absent or null.
    • has

      public boolean has(String name)
      True when the checkpoint holds weight name (under any accepted spelling).
    • floats

      public float[] floats(String name, int... shape)
      Weight name as FP32 values, checking its shape.
    • load

      public void load(Tensor target, String name)
      Copies weight name into parameter target of the same shape.
    • loadTransposed

      public void loadTransposed(Tensor target, String name)
      Copies the transpose of 2-D weight name into target (GPT-2's Conv1D layers store [in, out]).
    • loadConcatenated

      public void loadConcatenated(Tensor target, String... names)
      Copies the concatenation, along the first axis, of names into target.
    • unused

      public Set<String> unused()
      Weights of the checkpoint that no load call read, e.g. a head the model does not have.