ScaleFM
ScaleFM is a tool for scaling studies of deep learning pipelines: it searches how architectural and hyperparameter choices behave as you scale models, data, and compute, and fits scaling laws to predict the best choices at larger scales. Use it from a single GPU to a multi-node cluster or even multiple clusters.
ScaleFM unifies established and novel scaling prescriptions within the ScAn framework and pairs them with a runtime tailored to large-scale models. ScaleFM is actively maintained and used to run on many different clusters, tuning even billion-parameter scale models with many concurrent trials.
To learn about ScaleFM, check out the documentation or our examples.
Why ScaleFM
Scaling laws built in
- Search on a budget, predict at scale: scaling laws are integrated directly into the optimization loop, so that results obtained at small scale inform predictions of optimal configurations at larger scales.
- Cost-constrained sampling: optimizers restrict sampling to the feasible region of the search space, i.e., configurations that satisfy a user-specified black-box cost constraint.
- Predicting the optimal configuration at scale: ScaleFM answers the central question of any scaling study, namely which configuration to train at a target scale where a direct search is prohibitively expensive.
Tailored to large scale models
- Tuning distributed models: ScaleFM works with DDP and FSDP, on a single node or across multiple nodes, out of the box (examples).
- Zero-effort to run many concurrent models: start more workers on the same machine or in a multi-node setup. As long as they share the results directory, they coordinate on their own, with no server to set up.
- Live monitoring and interventions: follow a run with live plots or TensorBoard, and steer it without starting over: add workers, extend the budget, re-run failed trials, or import tuning results from anywhere (even cross-cluster).
Data acquisition and prediction algorithms
- Grounded prescriptions: established prescriptions from the literature, namely Chinchilla (Hoffmann et al., 2022), Kaplan (Kaplan et al., 2020), and CARBS (Fetterman et al., 2023), adapted to budget-aware search and complemented by our novel algorithm, ScAn-BO.
- Model-based search: strategies such as Bayesian optimization choose promising configurations smartly instead of sampling statically (e.g., Chinchilla) or at random.
Generally applicable
- Any design space: hyperparameters, architectures, resource allocation, or any component of the pipeline.
- Any scaling dimension: scale model size, dataset size, or any other quantity that sets the compute (
is_compute_scaling=True). - Downstream tasks: follow how downstream performances scale next to the pre-training loss.
- Training or inference cost: predictions can be made with respect to either training or inference compute.
Installation
ScaleFM supports Python 3.11 to 3.14. Install the latest release from PyPI:
pip install scalefm
Basic Usage
Using scalefm is based on the following pattern:
- Define a
pipeline_spaceof the parameters to search, marking those that scale the compute withis_compute_scaling=True. - Call
scalefm.acquire()with acost_estimatorand a cost budget to acquire data under a cost constraint. Withis_async=Trueit only samples the configurations; train each one as a job, which reports its result back withscalefm.save_pipeline_results(). Without it, pass anevaluate_pipelinefunction that trains a configuration and returns its result. - Call
scalefm.predict()to extrapolate the results to the target scale(s).
In code, the usage pattern can look like this:
import subprocess
from pathlib import Path
import yaml
import scalefm
ROOT_DIRECTORY = Path("path/to/save/results") # Replace with the actual path
# 1. Define the search space; the names match the arguments of the training job
class LMSpace(scalefm.PipelineSpace):
lr = scalefm.Float(lower=1e-4, upper=1e-2, log=True, prior=3e-4)
batch_size = scalefm.Integer(lower=64, upper=1024, log=True, log_base=2)
width = scalefm.Integer(lower=256, upper=4096, log=True, is_compute_scaling=True)
n_layers = scalefm.Integer(lower=4, upper=48, is_compute_scaling=True)
n_tokens = scalefm.Integer(lower=10**8, upper=10**11, log=True, is_compute_scaling=True)
# The training FLOPs of a configuration, known before it is evaluated
def estimate_flops(width: int, n_layers: int, n_tokens: int) -> float:
return 6 * (12 * n_layers * width**2) * n_tokens
# 2. Acquire data under the cost constraint: sample a round of configurations
scalefm.acquire(
pipeline_space=LMSpace(),
root_directory=ROOT_DIRECTORY,
cost_estimator=estimate_flops, # Cost of every configuration
max_cost_per_config=1e19, # Never sample a configuration costing more than this
total_cost_to_spend=1e20, # Budget for the whole search
is_async=True, # Only sample, the jobs below train the configurations
worker_evaluations_to_spend=8, # Configurations in this round
)
# 3. Train every new configuration as a multi-GPU job, which reports its result itself
for config_dir in sorted((ROOT_DIRECTORY / "configs").glob("config_*")):
submitted = config_dir / "submitted"
if submitted.exists():
continue
config = yaml.safe_load((config_dir / "config.yaml").read_text())
args = " ".join(f"--{name} {value}" for name, value in config.items())
pipeline_id = config_dir.name.removeprefix("config_")
subprocess.run(
f"sbatch --gpus=8 --wrap='torchrun --nproc_per_node=8 train.py "
f"--pipeline_id {pipeline_id} --root_directory {ROOT_DIRECTORY} {args}'",
shell=True,
check=True,
)
submitted.touch()
# 4. Once the jobs have reported, predict the optimal performance and configuration
# at the target scale(s)
predictions = scalefm.predict(
root_directory=ROOT_DIRECTORY,
target_costs=[1e22, 1e23],
) # The plots and their data are also saved to `root_directory/summary/`
The training job, train.py, reports its result back to ScaleFM when it finishes:
from pathlib import Path
import scalefm
args = parse_args() # lr, batch_size, width, n_layers, n_tokens, pipeline_id, root_directory
model = build_transformer(width=args.width, n_layers=args.n_layers) # Wrapped in DDP or FSDP
val_loss = train_and_eval(model, lr=args.lr, batch_size=args.batch_size, n_tokens=args.n_tokens)
if is_main_process():
scalefm.save_pipeline_results(
user_result={
"objective_to_minimize": val_loss,
"cost": 6 * model.n_params * args.n_tokens, # Training FLOPs
"n_params": model.n_params,
"n_data": args.n_tokens,
},
pipeline_id=args.pipeline_id,
root_directory=Path(args.root_directory),
live_plots=True, # Redraw the scaling plots with this result
)
See the evaluate_pipeline reference for the full asynchronous workflow.
Resources to Get Started
Tutorial
The ScaleFM Demo is a basic demo of what ScaleFM can do, on a TabPFN surrogate benchmark that runs on a CPU in a few minutes. It covers the basic pipeline, visualization, and parallelisation of the runs.
To run it locally instead, see the tutorials folder.
Examples
- Scaling study of TabPFN: a random search under a FLOP budget, with the scaling law fitted and extrapolated.
- Asynchronous evaluation: submit each configuration as a Slurm job and report its result back with
scalefm.save_pipeline_results(). - Scaling study of an OpenCLIP VLM: vision and text towers of varying width and depth, each trained in a Slurm job sized to its GPU memory needs.
- Distributed training: evaluate configurations with DDP or FSDP, in native PyTorch or PyTorch Lightning.
Documentation
- Getting started
- Reference: running ScaleFM, search spaces, optimizers, and analysing runs
- Scaling optimizers: cost-constrained search guided by scaling laws
- Algorithms
- API
Contributing
Please see the documentation for contributors.
Citing ScaleFM
To cite ScaleFM or the papers behind its algorithms, see our citation guide.
Metadata
Release files for scalefm 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scalefm-0.2.0.tar.gz | 232.6 kB | Without provenance | Details for scalefm-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scalefm-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for scalefm-0.2.0-py3-none-any.whl |
Total release size: 486.8 kB
Release files / scalefm-0.2.0.tar.gz
| Download URL | scalefm-0.2.0.tar.gz |
|---|---|
| Size | 232.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdcc8f43fd9226738ae12e7470a265cfd166348d75d177517c194278fa0cbb7e
|
|
BLAKE2b-256 checksum How to use checksums |
9e6350e45dc6df371ee2060ae87e4438a2f8826101f0df8104ce755d5f2f2eb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / scalefm-0.2.0-py3-none-any.whl
| Download URL | scalefm-0.2.0-py3-none-any.whl |
|---|---|
| Size | 254.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d02efa13dd96e432b3c8ab6d54b3c7b255dc3be18c0439323f39cfe87ec2d38c
|
|
BLAKE2b-256 checksum How to use checksums |
36a15f414f76ffd7846140764ca287086e265fcee28990c9c1b0e17808d2c4e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for scalefm 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.