pip install -r requirements.txtfrom astroml.storage import LocalArtifactStore
from astroml.tracking import MLflowTracker
store = LocalArtifactStore("./artifacts")
tracker = MLflowTracker(artifact_store=store)
# Save model
uri = tracker.log_model_artifact(model, checkpoint_path="best.pth")from astroml.storage import S3ArtifactStore
from astroml.tracking import MLflowTracker
store = S3ArtifactStore("my-bucket", "models")
tracker = MLflowTracker(artifact_store=store)
# Save model
uri = tracker.log_model_artifact(model, checkpoint_path="best.pth")from astroml.storage import GCSArtifactStore
from astroml.tracking import MLflowTracker
store = GCSArtifactStore("my-bucket", "models")
tracker = MLflowTracker(artifact_store=store)
# Save model
uri = tracker.log_model_artifact(model, checkpoint_path="best.pth")file:///path/to/artifacts # Local
s3://bucket-name/prefix # S3
gs://bucket-name/prefix # GCS
from astroml.storage import create_artifact_store
# Create from URI
store = create_artifact_store("s3://my-bucket/models")uri = store.save("local_file.pth", "remote/path.pth")store.load("remote/path.pth", "local_file.pth")if store.exists("remote/path.pth"):
print("Artifact exists")artifacts = store.list_artifacts("prefix")
for artifact in artifacts:
print(artifact)store.delete("remote/path.pth")uri = store.get_uri("remote/path.pth")
print(uri) # s3://bucket/prefix/remote/path.pthuri = tracker.log_model_artifact(
model=model,
artifact_path="model",
checkpoint_path="best.pth"
)uri = tracker.save_artifact(
local_path="config.yaml",
artifact_path="config"
)path = tracker.load_artifact(
remote_path="model/best.pth",
local_path="downloaded.pth"
)artifact_storage:
backend: local
local:
path: artifactsartifact_storage:
backend: s3
s3:
bucket: my-bucket
prefix: models
region_name: us-east-1artifact_storage:
backend: gcs
gcs:
bucket: my-bucket
prefix: models
project_id: my-projectexport AWS_ACCESS_KEY_ID=your_key
export AWS_SECRET_ACCESS_KEY=your_secret
export AWS_DEFAULT_REGION=us-east-1export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
export GOOGLE_CLOUD_PROJECT=my-projectfrom hydra import compose, initialize_config_dir
from astroml.storage import create_artifact_store
cfg = compose(config_name="config")
artifact_uri = cfg.training.artifact_storage.get_artifact_uri()
store = create_artifact_store(artifact_uri)# Run all tests
pytest tests/test_artifact_store.py -v
# Run specific test
pytest tests/test_artifact_store.py::TestLocalArtifactStore -v
# With coverage
pytest tests/test_artifact_store.py --cov=astroml.storage| Issue | Solution |
|---|---|
ModuleNotFoundError: fsspec |
pip install -r requirements.txt |
NoCredentialsError (S3) |
Set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY |
DefaultCredentialsError (GCS) |
Set GOOGLE_APPLICATION_CREDENTIALS |
PermissionError |
Verify IAM permissions |
FileNotFoundError |
Check artifact path exists |
from astroml.storage import LocalArtifactStore
store = LocalArtifactStore("./artifacts")
# Save
uri = store.save("model.pth", "exp1/model.pth")
print(f"Saved to: {uri}")
# Load
store.load("exp1/model.pth", "downloaded.pth")from astroml.storage import S3ArtifactStore
store = S3ArtifactStore("my-bucket", "models")
# List
artifacts = store.list_artifacts("exp1")
for artifact in artifacts:
print(artifact)
# Delete old ones
for artifact in artifacts:
if "old" in artifact:
store.delete(artifact)import os
from astroml.storage import create_artifact_store
# Use env var to switch backends
artifact_uri = os.getenv(
"ARTIFACT_URI",
"file:///tmp/artifacts"
)
store = create_artifact_store(artifact_uri)# Save local file to store
uri: str = store.save(local_path, remote_path)
# Load from store to local
path: Path = store.load(remote_path, local_path)
# Check if exists
exists: bool = store.exists(remote_path)
# Delete artifact
store.delete(remote_path)
# List artifacts
artifacts: list[str] = store.list_artifacts(prefix)
# Get full URI
uri: str = store.get_uri(remote_path)# Log model artifact
uri: Optional[str] = tracker.log_model_artifact(
model, artifact_path, checkpoint_path
)
# Save arbitrary artifact
uri: Optional[str] = tracker.save_artifact(
local_path, artifact_path
)
# Load artifact
path: Path = tracker.load_artifact(
remote_path, local_path
)- Use regional buckets for faster access
- Compress large models before upload
- Use multipart uploads (automatic for >100MB)
- Cache frequently accessed artifacts locally
- Use prefixes to organize artifacts
- Use environment variables for credentials
- Never commit credentials to version control
- Use IAM roles in production
- Enable bucket versioning
- Enable server-side encryption
- Restrict bucket access via policies
- Full Guide:
ARTIFACT_STORAGE.md - Integration:
ARTIFACT_STORE_INTEGRATION.md - Summary:
ARTIFACT_STORE_SUMMARY.md - Example:
examples/train_with_artifact_store.py
For issues or questions:
- Check
ARTIFACT_STORAGE.mdtroubleshooting section - Review example scripts
- Run tests to verify setup
- Check cloud provider documentation