Nasty.Statistics.Neural.Transformers.Config (Nasty v0.3.0)
View SourceConfiguration management for transformer models.
Provides centralized configuration via:
- Application config (config.exs)
- Environment variables
- Runtime options
Environment Variables
NASTY_MODEL_CACHE_DIR- Model cache locationNASTY_USE_GPU- Enable GPU acceleration (true/false)NASTY_TRANSFORMER_MODEL- Default transformer modelNASTY_HF_HOME- HuggingFace cache directory
Application Configuration
config :nasty, :transformers,
cache_dir: "priv/models/transformers",
default_model: :roberta_base,
backend: :exla,
device: :cpu,
offline_mode: false
Summary
Functions
Gets the numerical backend.
Gets the model cache directory.
Gets the default transformer model.
Gets the computation device (CPU or CUDA).
Gets the current transformer configuration.
Checks if offline mode is enabled.
Returns configuration as keyword list for passing to functions.
Validates configuration and provides helpful error messages.
Gets configuration with runtime options merged.
Types
Functions
@spec backend() :: backend()
Gets the numerical backend.
Examples
Config.backend()
# => :exla
@spec cache_dir() :: String.t()
Gets the model cache directory.
Checks in order:
- NASTY_MODEL_CACHE_DIR env var
- NASTY_HF_HOME env var (for compatibility)
- Application config
- Default: priv/models/transformers
Examples
Config.cache_dir()
# => "/home/user/.cache/nasty/transformers"
@spec default_model() :: atom()
Gets the default transformer model.
Examples
Config.default_model()
# => :roberta_base
@spec device() :: device()
Gets the computation device (CPU or CUDA).
Examples
Config.device()
# => :cpu
@spec get() :: config()
Gets the current transformer configuration.
Precedence (highest to lowest):
- Runtime options passed to functions
- Environment variables
- Application config
- Default config
Examples
Config.get()
# => %{cache_dir: "priv/models/transformers", ...}
Config.get(:cache_dir)
# => "priv/models/transformers"
@spec offline_mode?() :: boolean()
Checks if offline mode is enabled.
In offline mode, only cached models are used and no network requests are made to HuggingFace Hub.
Examples
Config.offline_mode?()
# => false
@spec to_keyword() :: keyword()
Returns configuration as keyword list for passing to functions.
Examples
Config.to_keyword()
# => [cache_dir: "...", default_model: :roberta_base, ...]
@spec validate!() :: :ok
Validates configuration and provides helpful error messages.
Examples
Config.validate!()
# => :ok (or raises if invalid)
Gets configuration with runtime options merged.
Examples
Config.with_opts(cache_dir: "/tmp/models", device: :cuda)
# => %{cache_dir: "/tmp/models", device: :cuda, ...}