-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(sdk): add prototype python wrapper for nexus #7373
Closed
Closed
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2f7e07f
add simple python lang support to nexus
raubitsj 12401f8
add ignore
raubitsj be39e4c
add protobuf interface stubs
raubitsj fb23617
add init/finish
raubitsj efc07f1
Merge branch 'main' into nexus-py-1
raubitsj f625f17
add new api stubs
raubitsj 5cd5f46
Merge remote-tracking branch 'origin/main' into nexus-py-1
raubitsj c26d951
add some run.log
raubitsj 6ddf86d
add new sdk example
raubitsj f8248cd
add new api
raubitsj f822051
update
raubitsj 45665f6
Update core/lang/py/examples/simple-newapi.py
kptkin 848e282
Update core/lang/py/examples/simple-newapi.py
kptkin e5623a1
Update core/lang/py/examples/simple-newapi.py
kptkin 5ec020e
add run.log for real
raubitsj 9826808
Merge branch 'nexus-py-1' of https://github.com/wandb/wandb into nexu…
raubitsj adf9008
add threadpool stuff
raubitsj df76156
add threadpool
raubitsj 843efcb
fix runkeeper race
raubitsj 3ae899b
exit nexus process if parent process goes away
raubitsj 2b9230c
update
raubitsj 51b9451
image upload from nexus works
raubitsj 1b56b60
handle images of different sizes
raubitsj a814e95
small tweak
raubitsj File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package processlib | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
const ( | ||
PRCTL_SYSCALL = 157 | ||
PR_SET_PDEATHSIG = 1 | ||
) | ||
|
||
func ShutdownOnParentDeath(parentPid int) { | ||
_, _, errno := syscall.Syscall(uintptr(PRCTL_SYSCALL), uintptr(PR_SET_PDEATHSIG), uintptr(syscall.SIGKILL), 0) | ||
if errno != 0 { | ||
os.Exit(127 + int(errno)) | ||
} | ||
// One last check... there is a possibility that the parent died right before the syscall was sent | ||
if os.Getppid() != parentPid { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build !linux | ||
|
||
package processlib | ||
|
||
func ShutdownOnParentDeath(parentPid int) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"C" | ||
"unsafe" | ||
"google.golang.org/protobuf/proto" | ||
"github.com/wandb/wandb/core/pkg/service" | ||
"github.com/wandb/wandb/core/pkg/gowandb/opts/runopts" | ||
) | ||
|
||
//export pbSessionSetup | ||
func pbSessionSetup() { | ||
wandbcoreSetup() | ||
} | ||
|
||
//export pbSessionTeardown | ||
func pbSessionTeardown() { | ||
// prob dont want this, we could share nexus across "sessions" | ||
wandbcoreTeardown() | ||
} | ||
|
||
//export pbRunStart | ||
func pbRunStart() int { | ||
options := []runopts.RunOption{} | ||
wandbcoreSetup() | ||
run, err := wandbSession.NewRun(options...) | ||
if err != nil { | ||
panic(err) | ||
} | ||
num := wandbRuns.Add(run) | ||
return num | ||
} | ||
|
||
//export pbRunLog | ||
func pbRunLog(num int, cBuffer *C.char, cLength C.int) { | ||
data := C.GoBytes(unsafe.Pointer(cBuffer), cLength) | ||
// Unmarshal protobuf | ||
msg := &service.DataRecord{} | ||
if err := proto.Unmarshal(data, msg); err != nil { | ||
return | ||
} | ||
// Process data (here simply prepending a string) | ||
run := wandbRuns.Get(num) | ||
|
||
dict := make(map[string]interface{}) | ||
for k, v := range msg.Item { | ||
switch value := v.DataType.(type) { | ||
case *service.DataValue_ValueInt: | ||
dict[k] = value.ValueInt | ||
case *service.DataValue_ValueDouble: | ||
dict[k] = value.ValueDouble | ||
case *service.DataValue_ValueString: | ||
dict[k] = value.ValueString | ||
} | ||
} | ||
|
||
run.Log(dict) | ||
} | ||
|
||
//export pbRunFinish | ||
func pbRunFinish(num int) { | ||
run := wandbRuns.Get(num) | ||
run.Finish() | ||
wandbRuns.Remove(num) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
time WANDB_BASE_URL=http://localhost:8080 $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env python | ||
import wandb | ||
|
||
runs = [wandb.init() for x in range(10)] | ||
for run in runs: | ||
run.log({"a": 1, "b": 2, "c": 4.0, "d": "blah"}) | ||
for run in runs: | ||
run.finish() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
time WANDB_MODE=offline $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
set -e | ||
rm -rf nexus-py-1 | ||
virtualenv nexus-py-1 | ||
source nexus-py-1/bin/activate | ||
pip install --upgrade pip | ||
cd ../lib | ||
./build_proto.sh | ||
./build_lib.sh | ||
pip install -e . | ||
echo "Run:" | ||
echo "source nexus-py-1/bin/activate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python | ||
import wandb | ||
|
||
""" | ||
Top level: | ||
new_api() -> API (? or sdk or library or core..or not) | ||
default_api | ||
default_session | ||
default_run | ||
(promote methods from default_api, default_session - and maybe default_run to top level namespace?) | ||
|
||
API: | ||
new_session -> Session | ||
|
||
Session: | ||
login() | ||
configure_auth() | ||
new_run() | ||
get_run() # might have mutable and readonly versions of the run? readonly by default? | ||
# alternate, prefix with object type? run_new, run_get... dont love | ||
# ? are api runs just like runapi --> can we log to a run from the public api? why not? | ||
|
||
Run: | ||
log() | ||
history() -> how does this work for a run in progress | ||
|
||
|
||
""" | ||
|
||
api = wandb.new_api() | ||
session = api.new_session() | ||
|
||
run = session.new_run() | ||
run_id = run.id | ||
run.log({"a": 1}) | ||
run.finish() | ||
|
||
run = session.get_run(run_id) | ||
for row in run.history(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env python | ||
import wandb | ||
|
||
wb = wandb.new_session() | ||
run = wb.new_run() | ||
run.log({"a": 1, "b": 2}) | ||
run.finish() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python | ||
import wandb | ||
|
||
run = wandb.init() | ||
run.log({"a": 1, "b": 2, "c": 4.0, "d": "blah"}) | ||
run.finish() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
from concurrent.futures import ThreadPoolExecutor | ||
import time | ||
import wandb | ||
|
||
wandb.setup() | ||
|
||
def do_run(): | ||
run = wandb.init() | ||
run.log({"a": 1, "b": 2, "c": 4.0, "d": "blah"}) | ||
run.finish() | ||
|
||
|
||
parser = argparse.ArgumentParser(description="benchmark wandb performance") | ||
parser.add_argument("--num-workers", "-n", type=int, default=20) | ||
args = parser.parse_args() | ||
|
||
jobs = [] | ||
with ThreadPoolExecutor(max_workers=args.num_workers) as executor: | ||
for _ in range(args.num_workers): | ||
jobs.append(executor.submit(do_run)) | ||
|
||
for job in jobs: | ||
_ = job.result() | ||
print("done?") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
recursive-include wandb *.py | ||
recursive-include wandb *.sh | ||
recursive-include wandb *.so | ||
recursive-exclude * __pycache__ | ||
recursive-exclude * *.py[co] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
BASE=../../ | ||
DEST=py/lib/ | ||
cd $BASE/ | ||
./scripts/base-build.sh | ||
mkdir -p $DEST/wandb/lib | ||
cp export/lib/libwandb_core.so $DEST/wandb/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
BASE=../../../.. | ||
DEST=core/lang/py/lib/ | ||
# cp $BASE/wandb/proto/*.proto wandb/proto/ | ||
cd $BASE/ | ||
protoc -I=. --python_out=$DEST wandb/proto/wandb_base.proto | ||
protoc -I=. --python_out=$DEST wandb/proto/wandb_internal.proto | ||
protoc -I=. --python_out=$DEST wandb/proto/wandb_telemetry.proto | ||
protoc -I=. --python_out=$DEST wandb/proto/wandb_settings.proto | ||
protoc -I=. --python_out=$DEST wandb/proto/wandb_server.proto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[build-system] | ||
requires = ['setuptools>61'] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "wandb" | ||
dynamic = ["version"] | ||
description = "A CLI and library for interacting with the Weights & Biases API." | ||
authors = [{ name = "Weights & Biases", email = "[email protected]" }] | ||
# readme = "package_readme.md" | ||
# license = { file = "LICENSE" } | ||
requires-python = ">=3.7" | ||
dependencies = [ | ||
"protobuf>=3.12.0,!=4.21.0,<5; python_version < '3.9' and sys_platform == 'linux'", | ||
"protobuf>=3.15.0,!=4.21.0,<5; python_version == '3.9' and sys_platform == 'linux'", | ||
"protobuf>=3.19.0,!=4.21.0,<5; python_version > '3.9' and sys_platform == 'linux'", | ||
"protobuf>=3.19.0,!=4.21.0,<5; sys_platform != 'linux'", | ||
"setuptools", | ||
] | ||
classifiers = [ | ||
"Development Status :: 5 - Production/Stable", | ||
"Intended Audience :: Developers", | ||
"Intended Audience :: Science/Research", | ||
"License :: OSI Approved :: MIT License", | ||
"Natural Language :: English", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Programming Language :: Python :: 3 :: Only", | ||
"Topic :: Scientific/Engineering :: Artificial Intelligence", | ||
"Topic :: Software Development :: Libraries :: Python Modules", | ||
"Topic :: System :: Logging", | ||
"Topic :: System :: Monitoring", | ||
] | ||
|
||
|
||
#[project.scripts] | ||
#wandb = "wandb.cli.cli:cli" | ||
#wb = "wandb.cli.cli:cli" | ||
|
||
[project.urls] | ||
"Source" = "https://github.com/wandb/wandb" | ||
"Bug Reports" = "https://github.com/wandb/wandb/issues" | ||
"Documentation" = "https://docs.wandb.ai/" | ||
|
||
[tool.setuptools] | ||
zip-safe = false | ||
packages = ["wandb"] | ||
package-dir = { "wandb" = "wandb" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from setuptools import setup | ||
|
||
setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
proto/ | ||
lib/ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
poor process :(