Migrate from Neptune Python client 1.x
Learn about the code changes that you must implement in your exisiting scripts before migrating from version 1.x
of the Neptune client library to neptune-scale.
Installation
pip install neptune
pip install neptune-scale
Import
import neptune
import neptune-scale
Run operations
For details on all parameters and methods, see Run.
Initialize a run
run = neptune.init_run()
run = neptune_scale.Run(
run_id=str(random()), # your custom run ID
...
)
sync()
run.sync()
run.wait_for_processing()
wait()
run.wait()
run.wait_for_submission()
Stop a run
run.stop()
run.close()
Logging metadata
For details on supported metadata types, see Attribute types reference.
Add tags
run["sys/tags"].add(["tag1", "tag2", ...])
run.add_tags(["tag1", "tag2", ...])
Add group tags
run["sys/group_tags"].add(["tag1", "tag2", ...])
run.add_tags(["tag1", "tag2", ...], group_tags=True)
Log a dictionary of values
run["config"] = stringify_unsupported(config_dict)
from datetime import datetime
SUPPORTED_DATATYPES = [int, float, str, datetime, bool, list, set]
for key in config_dict:
if type(parameters[key]) not in SUPPORTED_DATATYPES:
run.log_configs({f"config/{key}": str(parameters[key])})
else:
run.log_configs({f"config/{key}": parameters[key]})
stringify_unsupported()
isn't available in neptune-scale. Before logging, you must flatten all nested dictionaries and convert the data types to the supported ones.See an example function
def stringify_unsupported(d, parent_key="", sep="/"):
SUPPORTED_DATATYPES = [int, float, str, datetime, bool, list, set]
items = {}
if not isinstance(d, (dict, list, tuple, set)):
return d if type(d) in SUPPORTED_DATATYPES else str(d)
if isinstance(d, dict):
for k, v in d.items():
new_key = f"{parent_key}{sep}{k}" if parent_key else k
if isinstance(v, (dict, list, tuple, set)):
items |= stringify_unsupported(v, new_key, sep=sep)
else:
items[new_key] = v if type(v) in SUPPORTED_DATATYPES else str(v)
elif isinstance(d, (list, tuple, set)):
for i, v in enumerate(d):
new_key = f"{parent_key}{sep}{i}" if parent_key else str(i)
if isinstance(v, (dict, list, tuple, set)):
items.update(stringify_unsupported(v, new_key, sep=sep))
else:
items[new_key] = v if type(v) in SUPPORTED_DATATYPES else str(v)
return items
Log metrics
run["metrics"].append({"acc":acc, "loss":loss, ...})
run.log_metrics(data={"metrics/acc":acc,"metrics/loss":loss,...}, step=step)
log_metrics()
requires the step
parameter. An option to automatically increase the step
value isn't supported yet.