Transmuter.Repo (transmuter v2.0.0)

Copy Markdown View Source

A model repository: its configuration files and its ONNX files in each variant.

Hugging Face ONNX exports keep each component (model, encoder_model, decoder_model_merged, ...) in onnx/, in variants that differ by a suffix: model.onnx is fp32, model_q4.onnx has 4-bit weights, and so on. load!/2 reads the configuration of the repository, and component_file/3 picks the file of a component.

The variant of a component comes from, in this order:

  1. the :variant option, an atom such as :q4 or a map from component names to atoms
  2. the dtype of the transformers.js_config block in config.json, a string or a map
  3. the default that the task gives, when the repository has that file
  4. fp32, then the other variants in the order of @variants

A repository has two chat templates. :chat_template is that of the tokenizer: chat_template.jinja, else the template of tokenizer_config.json, else that of the processor. :processor_chat_template is that of the processor of a multimodal model, as ProcessorMixin of Python transformers 4.57 loads it: the template of chat_template.json, else chat_template.jinja, else the "chat_template" of processor_config.json.

Summary

Functions

Returns the path in the repository of the ONNX file of component (for example "model" or "decoder_model_merged"), in the variant that the rules of this module pick. default is the variant of the task.

Returns the id of the image token of a vision language model from config.json, or nil.

Reads the configuration files of source ({:hf, repo} or a local directory).

Returns the first result of read that is not nil, on the source of repo and then on the base model in its model card. read takes a source and reads the sentence-transformers files of that source, such as modules.json. ONNX exports often leave these files out, and their base model has them.

Returns the special token name (such as "pad" or "eos") as a string, or nil.

Returns the variants that the repository has for component.

Functions

component_file(repo, component, default \\ :fp32)

Returns the path in the repository of the ONNX file of component (for example "model" or "decoder_model_merged"), in the variant that the rules of this module pick. default is the variant of the task.

image_token_id(repo)

Returns the id of the image token of a vision language model from config.json, or nil.

The id is image_token_id, or else image_token_index, its other name in the attribute_map of Mistral3Config and LlavaConfig of Python transformers.

load!(source, opts \\ [])

Reads the configuration files of source ({:hf, repo} or a local directory).

A Hub source reads its file list from the Hub again, or from the cache when the Hub cannot be reached.

Options: :variant and the options of Transmuter.Hub.

load_component!(repo, component, default \\ :fp32, opts \\ [])

Loads the ONNX file of component with Transmuter.load!/2. opts go to Transmuter.load!/2.

sentence_transformers(repo, read)

Returns the first result of read that is not nil, on the source of repo and then on the base model in its model card. read takes a source and reads the sentence-transformers files of that source, such as modules.json. ONNX exports often leave these files out, and their base model has them.

When the Hub denies the base model, such as a gated model without a token or a model that does not exist, this function logs a warning and does not read it.

special_token(repo, name)

Returns the special token name (such as "pad" or "eos") as a string, or nil.

The token comes from special_tokens_map.json, then tokenizer_config.json, then the "extra_special_tokens" map of tokenizer_config.json, as in Python transformers. A token in these files is a string or a map with "content".

variants(repo, component)

Returns the variants that the repository has for component.