fal.toolkit package¶
Subpackages¶
- fal.toolkit.audio package
- fal.toolkit.file package
- fal.toolkit.image package
- fal.toolkit.utils package
- fal.toolkit.video package
Submodules¶
fal.toolkit.compilation module¶
PyTorch compilation cache management utilities.
This module provides utilities for managing PyTorch Inductor compilation caches across workers. When using torch.compile(), PyTorch generates optimized CUDA kernels on first run, which can take 20-30 seconds. By sharing these compiled kernels across workers, subsequent workers can load pre-compiled kernels in ~2 seconds instead of recompiling.
Typical usage in a model setup:
- Manual cache management:
dir_hash = load_inductor_cache(“mymodel/v1”) self.model = torch.compile(self.model) self.warmup() # Triggers compilation sync_inductor_cache(“mymodel/v1”, dir_hash)
- Context manager (automatic):
- with synchronized_inductor_cache(“mymodel/v1”):
self.model = torch.compile(self.model) self.warmup() # Compilation is automatically synced after
- fal.toolkit.compilation.get_gpu_type()¶
Detect the GPU type using nvidia-smi.
- Return type:
str- Returns:
The GPU model name (e.g., “H100”, “A100”, “H200”) or “UNKNOWN” if detection fails.
Example
>>> gpu_type = get_gpu_type() >>> print(f"Running on: {gpu_type}") Running on: H100
- fal.toolkit.compilation.load_inductor_cache(cache_key)¶
Load PyTorch Inductor compilation cache from global storage.
This function: 1. Sets TORCHINDUCTOR_CACHE_DIR environment variable 2. Looks for cached compiled kernels in GPU-specific global storage 3. Unpacks the cache to local temporary directory 4. Returns a hash of the unpacked directory for change detection
- Parameters:
cache_key (
str) – Unique identifier for this cache (e.g., “flux/2”, “mymodel/v1”)- Return type:
str- Returns:
Hash of the unpacked cache directory, or empty string if cache not found.
Example
>>> dir_hash = load_inductor_cache("flux/2") Found compilation cache at /data/inductor-caches/H100/flux/2.zip, unpacking... Cache unpacked successfully.
- fal.toolkit.compilation.sync_inductor_cache(cache_key, unpacked_dir_hash)¶
Sync updated PyTorch Inductor cache back to global storage.
This function: 1. Checks if the local cache has changed (by comparing hashes) 2. If changed, creates a zip archive of the new cache 3. Saves it to GPU-specific global storage
- Parameters:
cache_key (
str) – Unique identifier for this cache (same as used in load_inductor_cache)unpacked_dir_hash (
str) – Hash returned from load_inductor_cache (for change detection)
- Return type:
None
Example
>>> sync_inductor_cache("flux/2", dir_hash) No changes in the cache dir, skipping sync. # or Changes detected in the cache dir, syncing...
- fal.toolkit.compilation.synchronized_inductor_cache(cache_key)¶
Context manager to automatically load and sync PyTorch Inductor cache.
This wraps load_inductor_cache and sync_inductor_cache for convenience. The cache is loaded on entry and synced on exit (even if an exception occurs).
- Parameters:
cache_key (
str) – Unique identifier for this cache (e.g., “flux/2”, “mymodel/v1”)- Yields:
None
- Return type:
Iterator[None]
Example
>>> with synchronized_inductor_cache("mymodel/v1"): ... self.model = torch.compile(self.model) ... self.warmup() # Compilation happens here # Cache is automatically synced after the with block
fal.toolkit.exceptions module¶
- exception fal.toolkit.exceptions.FalTookitException¶
Bases:
ExceptionBase exception for all toolkit exceptions
- exception fal.toolkit.exceptions.FileUploadException¶
Bases:
FalTookitExceptionRaised when file upload fails
- exception fal.toolkit.exceptions.KVStoreException¶
Bases:
FalTookitExceptionRaised when KV store operation fails
fal.toolkit.kv module¶
- class fal.toolkit.kv.KVStore(db_name)¶
Bases:
objectA key-value store client for interacting with the FAL KV service.
- Parameters:
db_name (
str) – The name of the database/namespace to use for this KV store.
- property auth_headers: Dict[str, str]¶
- get(key)¶
Retrieve a value from the key-value store.
- Parameters:
key (
str) – The key to retrieve the value for.- Return type:
Optional[str]- Returns:
The value associated with the key, or None if the key doesn’t exist.
- set(key, value)¶
Store a value in the key-value store.
- Parameters:
key (
str) – The key to store the value under.value (
str) – The value to store.
- Return type:
None
fal.toolkit.pydantic module¶
- fal.toolkit.pydantic.AudioField(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
- class fal.toolkit.pydantic.FalBaseModel(**data)¶
Bases:
BaseModelBase model for fal applications with field ordering, visibility control, and context binding for error reporting.
Features: - FIELD_ORDERS: Control field order in JSON schema, useful for nested
models.
Hidden(Field(…)): Mark fields as hidden from OpenAPI schema, useful for hidden params.
Example
from fal.toolkit.pydantic import FalBaseModel, Field, Hidden
- class Input(FalBaseModel):
FIELD_ORDERS = [“prompt”, “image_url”]
prompt: str = Field(description=”Text prompt”) image_url: str = Field(description=”Image URL”) debug_mode: bool = Hidden(Field(default=False))
- FIELD_ORDERS: ClassVar[List[str]] = []¶
- SCHEMA_IGNORES: ClassVar[Set[str]] = {}¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- fal.toolkit.pydantic.Field(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
- fal.toolkit.pydantic.FileField(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
- fal.toolkit.pydantic.Hidden(field)¶
Wrapper that marks a Field as hidden in the UI.
The field MUST have a default or default_factory set since hidden fields cannot be required inputs in the UI.
- Usage:
- class Input(FalBaseModel):
prompt: str = Field(…) hidden_flag: bool = Hidden(Field(default=False))
- Parameters:
field (
TypeVar(_T)) – A pydantic FieldInfo instance (result of Field(…))- Return type:
TypeVar(_T)- Returns:
The same FieldInfo with hidden marker in metadata
- Raises:
ValueError – If field has no default or default_factory
- fal.toolkit.pydantic.ImageField(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
- fal.toolkit.pydantic.VideoField(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
fal.toolkit.types module¶
- class fal.toolkit.types.DataUri¶
Bases:
DownloadFileMixin,str
- class fal.toolkit.types.DownloadFileMixin¶
Bases:
object- as_temp_file()¶
- Return type:
Generator[Path,None,None]
- class fal.toolkit.types.HttpsUrl¶
Bases:
DownloadFileMixin,str
- class fal.toolkit.types.ImageDataUri¶
Bases:
DownloadImageMixin,DataUri
- class fal.toolkit.types.ImageHttpsUrl¶
Bases:
DownloadImageMixin,HttpsUrl
Module contents¶
- class fal.toolkit.Audio(**data)¶
Bases:
File- model_config: ClassVar[ConfigDict] = {'json_schema_extra': {'ui': {'field': 'audio'}}}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- fal.toolkit.AudioField(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
- class fal.toolkit.CompressedFile(**data)¶
Bases:
File- extract_dir: Optional[str]¶
- glob(pattern)¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- exception fal.toolkit.DownloadError¶
Bases:
Exception
- class fal.toolkit.FalBaseModel(**data)¶
Bases:
BaseModelBase model for fal applications with field ordering, visibility control, and context binding for error reporting.
Features: - FIELD_ORDERS: Control field order in JSON schema, useful for nested
models.
Hidden(Field(…)): Mark fields as hidden from OpenAPI schema, useful for hidden params.
Example
from fal.toolkit.pydantic import FalBaseModel, Field, Hidden
- class Input(FalBaseModel):
FIELD_ORDERS = [“prompt”, “image_url”]
prompt: str = Field(description=”Text prompt”) image_url: str = Field(description=”Image URL”) debug_mode: bool = Hidden(Field(default=False))
- FIELD_ORDERS: ClassVar[List[str]] = []¶
- SCHEMA_IGNORES: ClassVar[Set[str]] = {}¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- exception fal.toolkit.FalTookitException¶
Bases:
ExceptionBase exception for all toolkit exceptions
- fal.toolkit.Field(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
- class fal.toolkit.File(**data)¶
Bases:
BaseModel- as_bytes()¶
- Return type:
bytes
- content_type: Optional[str]¶
- file_data: Optional[bytes]¶
- file_name: Optional[str]¶
- file_size: Optional[int]¶
- classmethod from_bytes(data, content_type=None, file_name=None, repository='fal_v3', fallback_repository=['cdn', 'fal'], request=None, save_kwargs=None, fallback_save_kwargs=None)¶
- Return type:
- async classmethod from_bytes_async(data, content_type=None, file_name=None, repository='fal_v3', fallback_repository=['cdn', 'fal'], request=None, save_kwargs=None, fallback_save_kwargs=None)¶
- Return type:
- classmethod from_path(path, content_type=None, repository='fal_v3', multipart=None, fallback_repository=['cdn', 'fal'], request=None, save_kwargs=None, fallback_save_kwargs=None)¶
- Return type:
- async classmethod from_path_async(path, content_type=None, repository='fal_v3', multipart=None, fallback_repository=['cdn', 'fal'], request=None, save_kwargs=None, fallback_save_kwargs=None)¶
- Return type:
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- save(path, overwrite=False)¶
- Return type:
Path
- async save_async(path, overwrite=False)¶
- Return type:
Path
- url: str¶
- fal.toolkit.FileField(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
- exception fal.toolkit.FileUploadException¶
Bases:
FalTookitExceptionRaised when file upload fails
- fal.toolkit.Hidden(field)¶
Wrapper that marks a Field as hidden in the UI.
The field MUST have a default or default_factory set since hidden fields cannot be required inputs in the UI.
- Usage:
- class Input(FalBaseModel):
prompt: str = Field(…) hidden_flag: bool = Hidden(Field(default=False))
- Parameters:
field (
TypeVar(_T)) – A pydantic FieldInfo instance (result of Field(…))- Return type:
TypeVar(_T)- Returns:
The same FieldInfo with hidden marker in metadata
- Raises:
ValueError – If field has no default or default_factory
- class fal.toolkit.Image(**data)¶
Bases:
FileRepresents an image file.
- classmethod from_bytes(data, format, size=None, file_name=None, repository='fal_v3', fallback_repository=['cdn', 'fal'], request=None)¶
- Return type:
- classmethod from_pil(pil_image, format=None, file_name=None, repository='fal_v3', fallback_repository=['cdn', 'fal'], request=None)¶
- Return type:
- height: Optional[int]¶
- model_config: ClassVar[ConfigDict] = {'json_schema_extra': {'ui': {'field': 'image'}}}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- to_pil(mode='RGB')¶
- Return type:
Image
- width: Optional[int]¶
- fal.toolkit.ImageField(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
- class fal.toolkit.KVStore(db_name)¶
Bases:
objectA key-value store client for interacting with the FAL KV service.
- Parameters:
db_name (
str) – The name of the database/namespace to use for this KV store.
- property auth_headers: Dict[str, str]¶
- get(key)¶
Retrieve a value from the key-value store.
- Parameters:
key (
str) – The key to retrieve the value for.- Return type:
Optional[str]- Returns:
The value associated with the key, or None if the key doesn’t exist.
- set(key, value)¶
Store a value in the key-value store.
- Parameters:
key (
str) – The key to store the value under.value (
str) – The value to store.
- Return type:
None
- exception fal.toolkit.KVStoreException¶
Bases:
FalTookitExceptionRaised when KV store operation fails
- class fal.toolkit.Video(**data)¶
Bases:
File- model_config: ClassVar[ConfigDict] = {'json_schema_extra': {'ui': {'field': 'video'}}}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- fal.toolkit.VideoField(default=PydanticUndefined, *, default_factory=PydanticUndefined, alias=PydanticUndefined, alias_priority=PydanticUndefined, validation_alias=PydanticUndefined, serialization_alias=PydanticUndefined, title=PydanticUndefined, field_title_generator=PydanticUndefined, description=PydanticUndefined, examples=PydanticUndefined, exclude=PydanticUndefined, exclude_if=PydanticUndefined, discriminator=PydanticUndefined, deprecated=PydanticUndefined, json_schema_extra=PydanticUndefined, frozen=PydanticUndefined, validate_default=PydanticUndefined, repr=PydanticUndefined, init=PydanticUndefined, init_var=PydanticUndefined, kw_only=PydanticUndefined, pattern=PydanticUndefined, strict=PydanticUndefined, coerce_numbers_to_str=PydanticUndefined, gt=PydanticUndefined, ge=PydanticUndefined, lt=PydanticUndefined, le=PydanticUndefined, multiple_of=PydanticUndefined, allow_inf_nan=PydanticUndefined, max_digits=PydanticUndefined, decimal_places=PydanticUndefined, min_length=PydanticUndefined, max_length=PydanticUndefined, union_mode=PydanticUndefined, fail_fast=PydanticUndefined, **extra)¶
- !!! abstract “Usage Documentation”
[Fields](../concepts/fields.md)
Create a field for objects that can be configured.
Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.
Note
Any _Unset objects will be replaced by the corresponding value defined in the _DefaultValues dictionary. If a key for the _Unset object is not found in the _DefaultValues dictionary, it will default to None
- Parameters:
default (Any) – Default value if the field is not set.
default_factory (Callable[[], Any] | Callable[[dict[str, Any]], Any] | None) – A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.
alias (str | None) – The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.
alias_priority (int | None) – Priority of the alias. This affects whether an alias generator is used.
validation_alias (str | AliasPath | AliasChoices | None) – Like alias, but only affects validation, not serialization.
serialization_alias (str | None) – Like alias, but only affects serialization, not validation.
title (str | None) – Human-readable title.
field_title_generator (Callable[[str, FieldInfo], str] | None) – A callable that takes a field name and returns title for it.
description (str | None) – Human-readable description.
examples (list[Any] | None) – Example values for this field.
exclude (bool | None) – Whether to exclude the field from the model serialization.
exclude_if (Callable[[Any], bool] | None) – A callable that determines whether to exclude a field during serialization based on its value.
discriminator (str | types.Discriminator | None) – Field name or Discriminator for discriminating the type in a tagged union.
deprecated (Deprecated | str | bool | None) – A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.
json_schema_extra (JsonDict | Callable[[JsonDict], None] | None) – A dict or callable to provide extra JSON schema properties.
frozen (bool | None) – Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.
validate_default (bool | None) – If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.
repr (bool) – A boolean indicating whether to include the field in the __repr__ output.
init (bool | None) – Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)
init_var (bool | None) – Whether the field should _only_ be included in the constructor of the dataclass. (Only applies to dataclasses.)
kw_only (bool | None) – Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)
coerce_numbers_to_str (bool | None) – Whether to enable coercion of any Number type to str (not applicable in strict mode).
strict (bool | None) – If True, strict validation is applied to the field. See [Strict Mode](../concepts/strict_mode.md) for details.
gt (annotated_types.SupportsGt | None) – Greater than. If set, value must be greater than this. Only applicable to numbers.
ge (annotated_types.SupportsGe | None) – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.
lt (annotated_types.SupportsLt | None) – Less than. If set, value must be less than this. Only applicable to numbers.
le (annotated_types.SupportsLe | None) – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.
multiple_of (float | None) – Value must be a multiple of this. Only applicable to numbers.
min_length (int | None) – Minimum length for iterables.
max_length (int | None) – Maximum length for iterables.
pattern (str | re.Pattern[str] | None) – Pattern for strings (a regular expression).
allow_inf_nan (bool | None) – Allow inf, -inf, nan. Only applicable to float and [Decimal][decimal.Decimal] numbers.
max_digits (int | None) – Maximum number of allow digits for strings.
decimal_places (int | None) – Maximum number of decimal places allowed for numbers.
union_mode (Literal[‘smart’, ‘left_to_right’]) – The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See [Union Mode](../concepts/unions.md#union-modes) for details.
fail_fast (bool | None) – If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).
extra (Unpack[_EmptyKwargs]) –
(Deprecated) Extra fields that will be included in the JSON schema.
- !!! warning Deprecated
The extra kwargs is deprecated. Use json_schema_extra instead.
- Return type:
Any
- Returns:
- A new [FieldInfo][pydantic.fields.FieldInfo]. The return annotation is Any so Field can be used on
type-annotated fields without causing a type error.
- fal.toolkit.clone_repository(https_url, *, commit_hash=None, target_dir=None, repo_name=None, force=False, include_to_path=False)¶
Clones a Git repository from the specified HTTPS URL into a local directory.
This function clones a Git repository from the specified HTTPS URL into a local directory. It can also checkout a specific commit if the commit_hash is provided.
If a custom target_dir or repo_name is not specified, a predefined directory is used for the target directory, and the repository name is determined from the URL.
- Parameters:
https_url (
str) – The HTTPS URL of the Git repository to be cloned.commit_hash (
str|None) – The commit hash to checkout after cloning.target_dir (
str|Path|None) – The directory where the repository will be saved. If not provided, a predefined directory is used.repo_name (
str|None) – The name to be used for the cloned repository directory. If not provided, the repository’s name from the URL is used.force (
bool) – If True, the repository is cloned even if it already exists locally and its commit hash matches the provided commit hash. Defaults to False.include_to_path (
bool) – If True, the cloned repository is added to the sys.path. Defaults to False.
- Return type:
Path- Returns:
A Path object representing the full path to the cloned Git repository.
- fal.toolkit.download_file(url, target_dir, *, force=False, request_headers=None, filesize_limit=None)¶
Downloads a file from the specified URL to the target directory.
The function downloads the file from the given URL and saves it in the specified target directory, provided it is below the given filesize limit.
It also checks whether the local file already exists and whether its content length matches the expected content length from the remote file. If the local file already exists and its content length matches the expected content length from the remote file, the existing file is returned without re-downloading it.
If the file needs to be downloaded or if an existing file’s content length does not match the expected length, the function proceeds to download and save the file. It ensures that the target directory exists and handles any errors that may occur during the download process, raising a DownloadError if necessary.
- Parameters:
url (
str) – The URL of the file to be downloaded.target_dir (
str|Path) – The directory where the downloaded file will be saved. If it’s not an absolute path, it’s treated as a relative directory to “/data”.force (
bool) – If True, the file is downloaded even if it already exists locally and its content length matches the expected content length from the remote file. Defaults to False.request_headers (
dict[str,str] |None) – A dictionary containing additional headers to be included in the HTTP request. Defaults to None.filesize_limit (
int|None) – An integer specifying the maximum downloadable size, in megabytes. Defaults to None.
- Return type:
Path- Returns:
A Path object representing the full path to the downloaded file.
- Raises:
ValueError – If the provided file_name contains a forward slash (‘/’).
DownloadError – If an error occurs during the download process.
- fal.toolkit.download_model_weights(url, force=False, request_headers=None)¶
Downloads model weights from the specified URL and saves them to a predefined directory.
This function is specifically designed for downloading model weights and stores them in a predefined directory.
It calls the download_file function with the provided URL and the target directory set to a pre-defined location for model weights. The downloaded model weights are saved in this directory, and the function returns the full path to the downloaded weights file.
- Parameters:
url (
str) – The URL from which the model weights will be downloaded.force (
bool) – If True, the model weights are downloaded even if they already exist locally and their content length matches the expected content length from the remote file. Defaults to False.request_headers (
dict[str,str] |None) – A dictionary containing additional headers to be included in the HTTP request. Defaults to None.
- Return type:
Path- Returns:
A Path object representing the full path to the downloaded model weights.
- fal.toolkit.get_gpu_type()¶
Detect the GPU type using nvidia-smi.
- Return type:
str- Returns:
The GPU model name (e.g., “H100”, “A100”, “H200”) or “UNKNOWN” if detection fails.
Example
>>> gpu_type = get_gpu_type() >>> print(f"Running on: {gpu_type}") Running on: H100
- fal.toolkit.load_inductor_cache(cache_key)¶
Load PyTorch Inductor compilation cache from global storage.
This function: 1. Sets TORCHINDUCTOR_CACHE_DIR environment variable 2. Looks for cached compiled kernels in GPU-specific global storage 3. Unpacks the cache to local temporary directory 4. Returns a hash of the unpacked directory for change detection
- Parameters:
cache_key (
str) – Unique identifier for this cache (e.g., “flux/2”, “mymodel/v1”)- Return type:
str- Returns:
Hash of the unpacked cache directory, or empty string if cache not found.
Example
>>> dir_hash = load_inductor_cache("flux/2") Found compilation cache at /data/inductor-caches/H100/flux/2.zip, unpacking... Cache unpacked successfully.
- fal.toolkit.sync_inductor_cache(cache_key, unpacked_dir_hash)¶
Sync updated PyTorch Inductor cache back to global storage.
This function: 1. Checks if the local cache has changed (by comparing hashes) 2. If changed, creates a zip archive of the new cache 3. Saves it to GPU-specific global storage
- Parameters:
cache_key (
str) – Unique identifier for this cache (same as used in load_inductor_cache)unpacked_dir_hash (
str) – Hash returned from load_inductor_cache (for change detection)
- Return type:
None
Example
>>> sync_inductor_cache("flux/2", dir_hash) No changes in the cache dir, skipping sync. # or Changes detected in the cache dir, syncing...
- fal.toolkit.synchronized_inductor_cache(cache_key)¶
Context manager to automatically load and sync PyTorch Inductor cache.
This wraps load_inductor_cache and sync_inductor_cache for convenience. The cache is loaded on entry and synced on exit (even if an exception occurs).
- Parameters:
cache_key (
str) – Unique identifier for this cache (e.g., “flux/2”, “mymodel/v1”)- Yields:
None
- Return type:
Iterator[None]
Example
>>> with synchronized_inductor_cache("mymodel/v1"): ... self.model = torch.compile(self.model) ... self.warmup() # Compilation happens here # Cache is automatically synced after the with block