id int64 1 6.07M | name stringlengths 1 295 | code stringlengths 12 426k | language stringclasses 1
value | source_file stringlengths 5 202 | start_line int64 1 158k | end_line int64 1 158k | repo dict |
|---|---|---|---|---|---|---|---|
101 | check_files | def check_files(paths: List[Path]) -> None:
for p in paths:
generated_path = p.parent / str(p).replace(GENERATE_SUFFIX, GENERATED_SUFFIX)
print(f"INFO: Checking {generated_path}...")
with temp_fname() as temp_file:
generate_file(p, temp_file)
format_file(temp_file)
assert filecmp.cmp(
generated_path, temp_file
), f"expected: {open(temp_file).read()}" | python | tools/generate-tool.py | 97 | 106 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
102 | main | def main() -> None:
path_list = get_paths()
if args.generate:
generate_files(path_list)
if args.format:
format_files(path_list)
if args.check:
check_files(path_list) | python | tools/generate-tool.py | 109 | 118 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
103 | locate_py_files | def locate_py_files(root_path: pathlib.Path):
"""Recursively search for Python files in the given root directory."""
include = {root_path / dir_path for dir_path in CONFIG["include"]}
exclude = {root_path / dir_path for dir_path in CONFIG["exclude"]}
exclude_unrooted = CONFIG["exclude_unrooted"]
for path in map(str, root_path.rglob("*.py")):
if (
any(
path.startswith(str(root_path / dir_path))
for dir_path in map(pathlib.Path.absolute, include)
)
and all(
not path.startswith(str(root_path / dir_path))
for dir_path in map(pathlib.Path.absolute, exclude)
)
and all(dir_path not in path for dir_path in exclude_unrooted)
):
print(path) | python | tools/locate-py-files.py | 24 | 41 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
104 | __init__ | def __init__(self, size, num_samples):
self.len = num_samples
self.data = torch.randn(num_samples, size) | python | tests/functional_tests/t0_main/lightning/pl_base.py | 7 | 9 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
105 | __getitem__ | def __getitem__(self, index):
return self.data[index] | python | tests/functional_tests/t0_main/lightning/pl_base.py | 11 | 12 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
106 | __len__ | def __len__(self):
return self.len | python | tests/functional_tests/t0_main/lightning/pl_base.py | 14 | 15 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
107 | __init__ | def __init__(self):
super().__init__()
self.layer = torch.nn.Linear(32, 2) | python | tests/functional_tests/t0_main/lightning/pl_base.py | 19 | 21 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
108 | forward | def forward(self, x):
return self.layer(x) | python | tests/functional_tests/t0_main/lightning/pl_base.py | 23 | 24 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
109 | loss | def loss(self, batch, prediction):
# An arbitrary loss to have a loss that updates the model weights during `Trainer.fit` calls
return torch.nn.functional.mse_loss(prediction, torch.ones_like(prediction)) | python | tests/functional_tests/t0_main/lightning/pl_base.py | 26 | 28 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
110 | training_step | def training_step(self, batch, batch_idx):
output = self.layer(batch)
loss = self.loss(batch, output)
self.log("loss", loss)
return {"loss": loss} | python | tests/functional_tests/t0_main/lightning/pl_base.py | 30 | 34 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
111 | training_step_end | def training_step_end(self, training_step_outputs):
return training_step_outputs | python | tests/functional_tests/t0_main/lightning/pl_base.py | 36 | 37 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
112 | training_epoch_end | def training_epoch_end(self, outputs) -> None:
torch.stack([x["loss"] for x in outputs]).mean() | python | tests/functional_tests/t0_main/lightning/pl_base.py | 39 | 40 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
113 | validation_step | def validation_step(self, batch, batch_idx):
output = self.layer(batch)
loss = self.loss(batch, output)
return {"x": loss} | python | tests/functional_tests/t0_main/lightning/pl_base.py | 42 | 45 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
114 | validation_epoch_end | def validation_epoch_end(self, outputs) -> None:
torch.stack([x["x"] for x in outputs]).mean() | python | tests/functional_tests/t0_main/lightning/pl_base.py | 47 | 48 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
115 | test_step | def test_step(self, batch, batch_idx):
output = self.layer(batch)
loss = self.loss(batch, output)
self.log("fake_test_acc", loss)
return {"y": loss} | python | tests/functional_tests/t0_main/lightning/pl_base.py | 50 | 54 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
116 | test_epoch_end | def test_epoch_end(self, outputs) -> None:
torch.stack([x["y"] for x in outputs]).mean() | python | tests/functional_tests/t0_main/lightning/pl_base.py | 56 | 57 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
117 | configure_optimizers | def configure_optimizers(self):
optimizer = torch.optim.SGD(self.layer.parameters(), lr=0.1)
lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=1)
return [optimizer], [lr_scheduler] | python | tests/functional_tests/t0_main/lightning/pl_base.py | 59 | 62 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
118 | main | def main():
# Use concurrency experiment
wandb.require(experiment="service")
print("PIDPID", os.getpid())
# Set up data
num_samples = 100000
train = DataLoader(RandomDataset(32, num_samples), batch_size=32)
val = DataLoader(RandomDataset(32, num_samples), batch_size=32)
test = DataLoader(RandomDataset(32, num_samples), batch_size=32)
# init model
model = BoringModel()
# set up wandb
config = dict(some_hparam="Logged Before Trainer starts DDP")
wandb_logger = WandbLogger(log_model=True, config=config, save_code=True)
# Initialize a trainer
trainer = Trainer(
max_epochs=1,
logger=wandb_logger,
accelerator="tpu",
devices=8,
strategy="ddp",
)
# Train the model
trainer.fit(model, train, val)
trainer.test(test_dataloaders=test) | python | tests/functional_tests/t0_main/lightning/train_tpu_ddp.py | 12 | 40 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
119 | main | def main():
# Use concurrency experiment
print("PIDPID", os.getpid())
# Set up data
num_samples = 100000
train = RandomDataset(32, num_samples)
train = DataLoader(train, batch_size=32)
val = RandomDataset(32, num_samples)
val = DataLoader(val, batch_size=32)
test = RandomDataset(32, num_samples)
test = DataLoader(test, batch_size=32)
# init model
model = BoringModel()
# set up wandb
config = dict(some_hparam="Logged Before Trainer starts DDP")
wandb_logger = WandbLogger(log_model=True, config=config, save_code=True)
# Initialize a trainer
trainer = pl.Trainer(
max_epochs=1,
devices=2,
accelerator="cpu",
strategy="ddp",
logger=wandb_logger,
)
# Train the model
trainer.fit(model, train, val)
trainer.test(dataloaders=test) | python | tests/functional_tests/t0_main/lightning/t0_strategy_ddp.py | 10 | 40 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
120 | main | def main():
# Use concurrency experiment
print("PIDPID", os.getpid())
# Set up data
num_samples = 100000
train = DataLoader(RandomDataset(32, num_samples), batch_size=32)
val = DataLoader(RandomDataset(32, num_samples), batch_size=32)
test = DataLoader(RandomDataset(32, num_samples), batch_size=32)
# init model
model = BoringModel()
# set up wandb
config = dict(some_hparam="Logged Before Trainer starts DDP")
wandb_logger = WandbLogger(log_model=True, config=config, save_code=True)
# Initialize a trainer
trainer = Trainer(
max_epochs=1,
devices=2,
accelerator="cpu",
strategy="ddp_spawn",
logger=wandb_logger,
)
# Train the model
trainer.fit(model, train, val)
trainer.test(dataloaders=test) | python | tests/functional_tests/t0_main/lightning/t1_strategy_ddp_spawn.py | 10 | 37 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
121 | main | def main():
# Use concurrency experiment
wandb.require(experiment="service")
# boost stats logging frequency for testing
stats_settings = dict(_stats_sample_rate_seconds=0.5, _stats_samples_to_average=2)
wandb.setup(settings=stats_settings)
print("User process PID:", os.getpid())
# Set up data
num_samples = 100000
train = DataLoader(RandomDataset(32, num_samples), batch_size=32)
val = DataLoader(RandomDataset(32, num_samples), batch_size=32)
test = DataLoader(RandomDataset(32, num_samples), batch_size=32)
# init model
model = BoringModel()
# set up wandb
config = dict(some_hparam="Logged Before Trainer starts DDP")
wandb_logger = WandbLogger(
log_model=True,
config=config,
save_code=True,
name=pathlib.Path(__file__).stem,
)
# Initialize a trainer
trainer = Trainer(
max_epochs=2,
devices=2,
accelerator="gpu",
strategy="ddp",
logger=wandb_logger,
)
# Train the model
trainer.fit(model, train, val)
trainer.test(dataloaders=test) | python | tests/functional_tests/t0_main/lightning/train_gpu_ddp.py | 13 | 51 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
122 | main | def main():
with tempfile.TemporaryDirectory() as tmpdir:
with wandb.init() as run:
wandb.log({"metric": 5})
artifact = wandb.Artifact("test-artifact", "test-type")
with open(tmpdir + "/boom.txt", "w") as f:
f.write("testing")
local_path = f"{tmpdir}/boom.txt"
artifact.add_file(local_path, "boom/test-name")
artifact = run.log_artifact(artifact)
artifact.wait()
_ = use_model("test-artifact:latest") | python | tests/functional_tests/t0_main/artifacts/use-model-error.py | 7 | 20 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
123 | __init__ | def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10) | python | tests/functional_tests/t0_main/artifacts/link-model.py | 9 | 16 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
124 | forward | def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.dropout1(x)
x = torch.flatten(x, 1)
x = self.fc1(x)
x = F.relu(x)
x = self.dropout2(x)
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output | python | tests/functional_tests/t0_main/artifacts/link-model.py | 18 | 31 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
125 | main | def main():
my_model = Net()
wandb.init()
best_model = log_model(my_model, "my-model", aliases=["boom"], scope_project=True)
link_model(best_model, "entity/project/test_portfolio")
wandb.finish() | python | tests/functional_tests/t0_main/artifacts/link-model.py | 34 | 43 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
126 | make_image | def make_image():
return wandb.Image(np.random.randint(255, size=(32, 32))) | python | tests/functional_tests/t0_main/artifacts/log-image-artifact-path.py | 5 | 6 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
127 | main | def main():
# Base Case
with wandb.init() as run:
run.log({"image": make_image()})
# With Logged Target
with wandb.init() as run:
art = wandb.Artifact("examples", "images")
image = make_image()
art.add(image, "image")
run.log_artifact(art)
run.log({"image": image}) | python | tests/functional_tests/t0_main/artifacts/log-image-artifact-path.py | 9 | 20 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
128 | __init__ | def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10) | python | tests/functional_tests/t0_main/artifacts/link-model-outside-run.py | 10 | 17 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
129 | forward | def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.dropout1(x)
x = torch.flatten(x, 1)
x = self.fc1(x)
x = F.relu(x)
x = self.dropout2(x)
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output | python | tests/functional_tests/t0_main/artifacts/link-model-outside-run.py | 19 | 32 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
130 | main | def main():
my_model = Net()
sm = _SavedModel.init(my_model)
art = wandb.Artifact("my-model", "model")
art.add(sm, "index")
link_model(sm, "entity/project/test_portfolio") | python | tests/functional_tests/t0_main/artifacts/link-model-outside-run.py | 35 | 41 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
131 | __init__ | def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10) | python | tests/functional_tests/t0_main/artifacts/use-and-link-model.py | 10 | 17 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
132 | forward | def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.dropout1(x)
x = torch.flatten(x, 1)
x = self.fc1(x)
x = F.relu(x)
x = self.dropout2(x)
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output | python | tests/functional_tests/t0_main/artifacts/use-and-link-model.py | 19 | 32 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
133 | main | def main():
run = wandb.init()
my_model = Net()
sm = _SavedModel.init(my_model)
art = wandb.Artifact("my-model", "model")
art.add(sm, "index")
art = run.log_artifact(art)
art.wait()
sm = use_model("my-model:latest")
link_model(sm, "entity/project/test_portfolio")
run.finish() | python | tests/functional_tests/t0_main/artifacts/use-and-link-model.py | 35 | 50 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
134 | __init__ | def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10) | python | tests/functional_tests/t0_main/artifacts/public-link-model.py | 8 | 15 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
135 | forward | def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.dropout1(x)
x = torch.flatten(x, 1)
x = self.fc1(x)
x = F.relu(x)
x = self.dropout2(x)
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output | python | tests/functional_tests/t0_main/artifacts/public-link-model.py | 17 | 30 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
136 | main | def main():
# create an artifact
# call .wait() to get a Public Artifact bound to it
# and then do link on that artifact
run = wandb.init()
with open("my-dataset.txt", "w") as fp:
fp.write("this-is-data")
art = wandb.Artifact("my-art-name", "my-art-type")
art.add_file("my-dataset.txt")
art = run.log_artifact(art)
art.wait()
art._logged_artifact._instance.link("entity/project/test_portfolio", aliases="best")
run.finish() | python | tests/functional_tests/t0_main/artifacts/public-link-model.py | 33 | 45 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
137 | main | def main():
with tempfile.TemporaryDirectory() as tmpdir:
with wandb.init() as run:
wandb.log({"metric": 5})
artifact = wandb.Artifact("test-artifact", "test-type")
with open(tmpdir + "/boom.txt", "w") as f:
f.write("testing")
local_path = f"{tmpdir}/boom.txt"
artifact.add_file(local_path, "index/test-name")
artifact = run.log_artifact(artifact)
artifact.wait()
_ = use_model("test-artifact:latest") | python | tests/functional_tests/t0_main/artifacts/use-model-outside-run-error.py | 7 | 20 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
138 | main | def main():
with tempfile.TemporaryDirectory() as tmpdir:
with wandb.init() as run:
wandb.log({"metric": 5})
artifact = wandb.Artifact("test-artifact", "model")
with open(tmpdir + "/boom.txt", "w") as f:
f.write("testing")
local_path = f"{tmpdir}/boom.txt"
artifact.add_file(local_path, "test-name")
run.link_artifact(artifact, "entity/project/test_portfolio") | python | tests/functional_tests/t0_main/artifacts/link-artifact.py | 10 | 20 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
139 | main | def main():
run = wandb.init(entity="mock_server_entity", project="test")
art = wandb.Artifact("test_artifact", type="model")
art.add_file("public_collection.py")
run.link_artifact(art, "mock_server_entity/test/test_port")
run.finish()
collections = wandb.Api().artifact_type("model", "test").collections()
assert len(collections) == 2 | python | tests/functional_tests/t0_main/artifacts/public_collections.py | 4 | 12 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
140 | main | def main():
with tempfile.TemporaryDirectory() as tmpdir:
with wandb.init() as run:
wandb.log({"metric": 5})
artifact = wandb.Artifact("test-artifact", "test-type")
with open(tmpdir + "/boom.txt", "w") as f:
f.write("testing")
local_path = f"{tmpdir}/boom.txt"
artifact.add_file(local_path, "test-name")
run.log_artifact(artifact) | python | tests/functional_tests/t0_main/artifacts/log-artifact.py | 6 | 16 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
141 | __init__ | def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10) | python | tests/functional_tests/t0_main/artifacts/use-model.py | 10 | 17 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
142 | forward | def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.dropout1(x)
x = torch.flatten(x, 1)
x = self.fc1(x)
x = F.relu(x)
x = self.dropout2(x)
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output | python | tests/functional_tests/t0_main/artifacts/use-model.py | 19 | 32 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
143 | main | def main():
run = wandb.init(entity="mock_server_entity", project="test")
my_model = Net()
sm = _SavedModel.init(my_model)
art = wandb.Artifact("my-model", "model")
art.add(sm, "index")
art = run.log_artifact(art)
art.wait()
_ = use_model("my-model:latest")
run.finish() | python | tests/functional_tests/t0_main/artifacts/use-model.py | 35 | 49 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
144 | __init__ | def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10) | python | tests/functional_tests/t0_main/artifacts/log-model.py | 9 | 16 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
145 | forward | def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.dropout1(x)
x = torch.flatten(x, 1)
x = self.fc1(x)
x = F.relu(x)
x = self.dropout2(x)
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output | python | tests/functional_tests/t0_main/artifacts/log-model.py | 18 | 31 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
146 | main | def main():
my_model = Net()
_ = log_model(my_model, "my-model", aliases=["boom"], scope_project=True)
wandb.finish() | python | tests/functional_tests/t0_main/artifacts/log-model.py | 34 | 39 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
147 | main | def main():
with wandb.init() as run:
artifact = wandb.Artifact("my_artifact", type="unicode_artifact")
with artifact.new_file("euler.txt", mode="w", encoding="utf-8") as f:
f.write("e^(iπ)+1=0")
run.log_artifact(artifact) | python | tests/functional_tests/t0_main/artifacts/log-unicode-artifact.py | 4 | 10 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
148 | make_env | def make_env():
env = gym.make(config["env_name"])
env = Monitor(env) # record stats such as returns
return env | python | tests/functional_tests/t0_main/sb3/t1_stable_baselines3.py | 24 | 27 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
149 | train | def train(layers, epochs):
for n in range(layers or 10):
print(f"Layer: {n}")
for n in range(epochs or 10):
print(f"Epoch: {n}") | python | tests/functional_tests/t0_main/magic/t2_no_keras.py | 26 | 30 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
150 | main | def main():
assert "tensorflow" not in sys.modules
parser = argparse.ArgumentParser()
parser.add_argument("--layers", type=int, help="num layers")
parser.add_argument("--epochs", type=int, default=4, help="num epochs")
args = parser.parse_args()
train(args.layers, args.epochs) | python | tests/functional_tests/t0_main/magic/t2_no_keras.py | 33 | 39 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
151 | process_child | def process_child(run):
# need to re-seed the rng otherwise we get image collision
rng = np.random.default_rng(os.getpid())
height = width = 2
media = [wandb.Image(rng.random((height, width))) for _ in range(3)]
run.log({"media": media}) | python | tests/functional_tests/t0_main/grpc/t2_mp_log_image_sequence.py | 15 | 21 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
152 | main | def main():
# Temporary environment variable for testing grpc service mode
os.environ["WANDB_SERVICE_TRANSPORT"] = "grpc"
wandb.require("service")
run = wandb.init()
# Start a new run in parallel in a child process
processes = [
mp.Process(target=process_child, kwargs=dict(run=run)) for _ in range(2)
]
for p in processes:
p.start()
for p in processes:
p.join()
run.finish() | python | tests/functional_tests/t0_main/grpc/t2_mp_log_image_sequence.py | 24 | 42 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
153 | objective | def objective(config, checkpoint_dir=None):
for _i in range(30):
loss = config["mean"] + config["sd"] * np.random.randn()
session.report({"loss": loss}) | python | tests/functional_tests/t0_main/raytune/t2_callback.py | 14 | 17 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
154 | tune_function | def tune_function(api_key_file):
"""Example for using a WandbLoggerCallback with the function API."""
tuner = tune.Tuner(
objective,
tune_config=tune.TuneConfig(
metric="loss",
mode="min",
),
run_config=air.RunConfig(
callbacks=[
WandbLoggerCallback(api_key_file=api_key_file, project="Wandb_example")
],
),
param_space={
"mean": tune.grid_search([1, 2, 3, 4, 5]),
"sd": tune.uniform(0.2, 0.8),
},
)
results = tuner.fit()
return results.get_best_result().config | python | tests/functional_tests/t0_main/raytune/t2_callback.py | 20 | 40 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
155 | main | def main():
api_key_file = get_wandb_api_key_file()
tune_function(api_key_file) | python | tests/functional_tests/t0_main/raytune/t2_callback.py | 43 | 45 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
156 | train_fn | def train_fn(config):
for _i in range(10):
loss = config["a"] + config["b"]
wandb.log({"loss": loss})
tune.report(loss=loss) | python | tests/functional_tests/t0_main/raytune/t1_example.py | 17 | 21 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
157 | decorated_objective | def decorated_objective(config, checkpoint_dir=None):
for _i in range(30):
loss = config["mean"] + config["sd"] * np.random.randn()
session.report({"loss": loss})
wandb.log(dict(loss=loss)) | python | tests/functional_tests/t0_main/raytune/t3_mixin.py | 16 | 20 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
158 | tune_decorated | def tune_decorated(api_key_file):
"""Example for using the @wandb_mixin decorator with the function API."""
tuner = tune.Tuner(
decorated_objective,
tune_config=tune.TuneConfig(
metric="loss",
mode="min",
),
param_space={
"mean": tune.grid_search([1, 2, 3, 4, 5]),
"sd": tune.uniform(0.2, 0.8),
"wandb": {"api_key_file": api_key_file, "project": "Wandb_example"},
},
)
results = tuner.fit()
return results.get_best_result().config | python | tests/functional_tests/t0_main/raytune/t3_mixin.py | 23 | 39 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
159 | main | def main():
api_key_file = get_wandb_api_key_file()
tune_decorated(api_key_file) | python | tests/functional_tests/t0_main/raytune/t3_mixin.py | 42 | 44 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
160 | train_mnist | def train_mnist(config):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
train_loader, test_loader = get_data_loaders()
model = ConvNet()
model.to(device)
optimizer = optim.SGD(
model.parameters(), lr=config["lr"], momentum=config["momentum"]
)
for _i in range(5):
train(model, optimizer, train_loader, device=device)
acc = test(model, test_loader, device=device)
# When using WandbLogger, the metrics reported to tune are also logged in the W&B dashboard
tune.report(mean_accuracy=acc)
# @wandb_mixin enables logging custom metrics using wandb.log()
error_rate = 100 * (1 - acc)
wandb.log({"error_rate": error_rate}) | python | tests/functional_tests/t0_main/raytune/t5_colab.py | 20 | 41 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
161 | run | def run():
torch.backends.cudnn.deterministic = True
random.seed(2022)
np.random.seed(2022)
torch.manual_seed(2022)
torch.cuda.manual_seed_all(2022)
wandb.login()
wandb_init = {"project": "raytune-colab"}
analysis = tune.run(
train_mnist,
loggers=[WandbLogger],
resources_per_trial={"gpu": 0},
config={
# wandb dict accepts all arguments that can be passed in wandb.init()
"wandb": wandb_init,
# hyperparameters are set by keyword arguments
"lr": tune.grid_search([0.0001, 0.001, 0.1]),
"momentum": tune.grid_search([0.9, 0.99]),
},
)
print("Best config: ", analysis.get_best_config(metric="mean_accuracy", mode="max")) | python | tests/functional_tests/t0_main/raytune/t5_colab.py | 44 | 67 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
162 | step | def step(self):
for _i in range(30):
loss = self.config["mean"] + self.config["sd"] * np.random.randn()
wandb.log({"loss": loss})
return {"loss": loss, "done": True} | python | tests/functional_tests/t0_main/raytune/t4_trainable.py | 16 | 20 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
163 | tune_trainable | def tune_trainable(api_key_file):
"""Example for using a WandTrainableMixin with the class API."""
tuner = tune.Tuner(
WandbTrainable,
tune_config=tune.TuneConfig(
metric="loss",
mode="min",
),
param_space={
"mean": tune.grid_search([1, 2, 3, 4, 5]),
"sd": tune.uniform(0.2, 0.8),
"wandb": {"api_key_file": api_key_file, "project": "Wandb_example"},
},
)
results = tuner.fit()
return results.get_best_result().config | python | tests/functional_tests/t0_main/raytune/t4_trainable.py | 23 | 39 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
164 | main | def main():
api_key_file = get_wandb_api_key_file()
tune_trainable(api_key_file) | python | tests/functional_tests/t0_main/raytune/t4_trainable.py | 42 | 44 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
165 | get_wandb_api_key | def get_wandb_api_key() -> str:
base_url = os.environ.get("WANDB_BASE_URL", "https://api.wandb.ai")
api_key = os.environ.get("WANDB_API_KEY")
if not api_key:
auth = requests.utils.get_netrc_auth(base_url)
if not auth:
raise ValueError(
f"must configure api key by env or in netrc for {base_url}"
)
api_key = auth[-1]
return api_key | python | tests/functional_tests/t0_main/raytune/_test_support.py | 6 | 16 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
166 | get_wandb_api_key_file | def get_wandb_api_key_file(file_name: str = None) -> str:
file_name = file_name or ".wandb-api-key.secret"
api_key = get_wandb_api_key()
with open(file_name, "w") as f:
f.write(api_key)
return os.path.abspath(file_name) | python | tests/functional_tests/t0_main/raytune/_test_support.py | 19 | 24 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
167 | run_first | def run_first() -> str:
with wandb.init() as run:
assert not run.resumed
wandb.log(dict(m1=1))
wandb.log(dict(m2=2))
wandb.log(dict(m3=3))
run_id = run.id
run_path = run.path
return run_id, run_path | python | tests/functional_tests/t0_main/resume/two_runs.py | 8 | 16 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
168 | run_again | def run_again(run_id: str, resume: Optional[str]) -> None:
kwargs = dict(id=run_id)
if resume:
kwargs["resume"] = resume
with wandb.init(**kwargs) as run:
if run.resumed:
print("RUN_STATE: run resumed")
else:
print("RUN_STATE: run not resumed")
wandb.log(dict(m1=11))
wandb.log(dict(m2=22))
wandb.log(dict(m4=44)) | python | tests/functional_tests/t0_main/resume/two_runs.py | 19 | 30 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
169 | delete_run | def delete_run(run_path: str) -> None:
api = wandb.Api()
run = api.run(run_path)
print(f"Deleting: {run_path}...")
run.delete()
print("done.") | python | tests/functional_tests/t0_main/resume/two_runs.py | 33 | 38 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
170 | main | def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--resume", type=str)
parser.add_argument("--delete_run", action="store_true")
args = parser.parse_args()
run_id, run_path = run_first()
if args.delete_run:
delete_run(run_path)
run_again(run_id=run_id, resume=args.resume) | python | tests/functional_tests/t0_main/resume/two_runs.py | 41 | 51 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
171 | cfg | def cfg():
c = 1.0 # noqa: F841
gamma = 0.7 # noqa: F841 | python | tests/functional_tests/t0_main/sacred/t1_regression.py | 11 | 13 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
172 | run | def run(c, gamma):
iris = datasets.load_iris()
per = permutation(iris.target.size)
iris.data = iris.data[per]
iris.target = iris.target[per]
clf = svm.SVC(C=c, kernel="rbf", gamma=gamma)
clf.fit(iris.data[:90], iris.target[:90])
return clf.score(iris.data[90:], iris.target[90:]) | python | tests/functional_tests/t0_main/sacred/t1_regression.py | 17 | 24 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
173 | add_wandb_env_variables | def add_wandb_env_variables(op):
env = {
"WANDB_API_KEY": os.getenv("WANDB_API_KEY"),
"WANDB_BASE_URL": os.getenv("WANDB_BASE_URL"),
"WANDB_KUBEFLOW_URL": os.getenv("WANDB_KUBEFLOW_URL"),
"WANDB_PROJECT": "wandb_kfp_integration_test",
}
for name, value in env.items():
op = op.add_env_variable(V1EnvVar(name, value))
return op | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 12 | 22 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
174 | preprocess_data | def preprocess_data(
X_train_path: components.OutputPath("np_array"), # noqa: F821,N803
X_test_path: components.OutputPath("np_array"), # noqa: F821,N803
y_train_path: components.OutputPath("np_array"), # noqa: F821
y_test_path: components.OutputPath("np_array"), # noqa: F821
mlpipeline_ui_metadata_path: components.OutputPath(),
seed: int = 1337,
):
import json
import numpy as np
import wandb
from sklearn import datasets
from sklearn.model_selection import train_test_split
def add_wandb_visualization(run, mlpipeline_ui_metadata_path):
"""NOTE: To use this, you must modify your component to have an output called `mlpipeline_ui_metadata_path` AND call `wandb.init` yourself inside that component.
Example usage:
def my_component(..., mlpipeline_ui_metadata_path: OutputPath()):
import wandb
from wandb.integration.kfp.helpers import add_wandb_visualization
with wandb.init() as run:
add_wandb_visualization(run, mlpipeline_ui_metadata_path)
... # the rest of your code here
"""
def get_iframe_html(run):
return f'<iframe src="{run.url}?kfp=true" style="border:none;width:100%;height:100%;min-width:900px;min-height:600px;"></iframe>'
iframe_html = get_iframe_html(run)
metadata = {
"outputs": [
{"type": "markdown", "storage": "inline", "source": iframe_html}
]
}
with open(mlpipeline_ui_metadata_path, "w") as metadata_file:
json.dump(metadata, metadata_file)
with wandb.init() as run:
add_wandb_visualization(run, mlpipeline_ui_metadata_path)
X, y = datasets.load_iris(return_X_y=True) # noqa: N806
X_train, X_test, y_train, y_test = train_test_split( # noqa: N806
X, y, test_size=0.2, random_state=seed
)
with open(X_train_path, "wb") as f:
np.save(f, X_train)
with open(y_train_path, "wb") as f:
np.save(f, y_train)
with open(X_test_path, "wb") as f:
np.save(f, X_test)
with open(y_test_path, "wb") as f:
np.save(f, y_test) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 25 | 86 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
175 | add_wandb_visualization | def add_wandb_visualization(run, mlpipeline_ui_metadata_path):
"""NOTE: To use this, you must modify your component to have an output called `mlpipeline_ui_metadata_path` AND call `wandb.init` yourself inside that component.
Example usage:
def my_component(..., mlpipeline_ui_metadata_path: OutputPath()):
import wandb
from wandb.integration.kfp.helpers import add_wandb_visualization
with wandb.init() as run:
add_wandb_visualization(run, mlpipeline_ui_metadata_path)
... # the rest of your code here
"""
def get_iframe_html(run):
return f'<iframe src="{run.url}?kfp=true" style="border:none;width:100%;height:100%;min-width:900px;min-height:600px;"></iframe>'
iframe_html = get_iframe_html(run)
metadata = {
"outputs": [
{"type": "markdown", "storage": "inline", "source": iframe_html}
]
}
with open(mlpipeline_ui_metadata_path, "w") as metadata_file:
json.dump(metadata, metadata_file) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 40 | 66 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
176 | get_iframe_html | def get_iframe_html(run):
return f'<iframe src="{run.url}?kfp=true" style="border:none;width:100%;height:100%;min-width:900px;min-height:600px;"></iframe>' | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 55 | 56 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
177 | train_model | def train_model(
X_train_path: components.InputPath("np_array"), # noqa: F821,N803
y_train_path: components.InputPath("np_array"), # noqa: F821
model_path: components.OutputPath("sklearn_model"), # noqa: F821
mlpipeline_ui_metadata_path: components.OutputPath(),
):
import json
import joblib
import numpy as np
import wandb
from sklearn.ensemble import RandomForestClassifier
def add_wandb_visualization(run, mlpipeline_ui_metadata_path):
"""NOTE: To use this, you must modify your component to have an output called `mlpipeline_ui_metadata_path` AND call `wandb.init` yourself inside that component.
Example usage:
def my_component(..., mlpipeline_ui_metadata_path: OutputPath()):
import wandb
from wandb.integration.kfp.helpers import add_wandb_visualization
with wandb.init() as run:
add_wandb_visualization(run, mlpipeline_ui_metadata_path)
... # the rest of your code here
"""
def get_iframe_html(run):
return f'<iframe src="{run.url}?kfp=true" style="border:none;width:100%;height:100%;min-width:900px;min-height:600px;"></iframe>'
iframe_html = get_iframe_html(run)
metadata = {
"outputs": [
{"type": "markdown", "storage": "inline", "source": iframe_html}
]
}
with open(mlpipeline_ui_metadata_path, "w") as metadata_file:
json.dump(metadata, metadata_file)
with wandb.init() as run:
add_wandb_visualization(run, mlpipeline_ui_metadata_path)
with open(X_train_path, "rb") as f:
X_train = np.load(f) # noqa: N806
with open(y_train_path, "rb") as f:
y_train = np.load(f)
model = RandomForestClassifier()
model.fit(X_train, y_train)
joblib.dump(model, model_path) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 89 | 142 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
178 | add_wandb_visualization | def add_wandb_visualization(run, mlpipeline_ui_metadata_path):
"""NOTE: To use this, you must modify your component to have an output called `mlpipeline_ui_metadata_path` AND call `wandb.init` yourself inside that component.
Example usage:
def my_component(..., mlpipeline_ui_metadata_path: OutputPath()):
import wandb
from wandb.integration.kfp.helpers import add_wandb_visualization
with wandb.init() as run:
add_wandb_visualization(run, mlpipeline_ui_metadata_path)
... # the rest of your code here
"""
def get_iframe_html(run):
return f'<iframe src="{run.url}?kfp=true" style="border:none;width:100%;height:100%;min-width:900px;min-height:600px;"></iframe>'
iframe_html = get_iframe_html(run)
metadata = {
"outputs": [
{"type": "markdown", "storage": "inline", "source": iframe_html}
]
}
with open(mlpipeline_ui_metadata_path, "w") as metadata_file:
json.dump(metadata, metadata_file) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 102 | 128 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
179 | get_iframe_html | def get_iframe_html(run):
return f'<iframe src="{run.url}?kfp=true" style="border:none;width:100%;height:100%;min-width:900px;min-height:600px;"></iframe>' | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 117 | 118 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
180 | test_model | def test_model(
X_test_path: components.InputPath("np_array"), # noqa: F821,N803
y_test_path: components.InputPath("np_array"), # noqa: F821
model_path: components.InputPath("sklearn_model"), # noqa: F821
mlpipeline_ui_metadata_path: components.OutputPath(),
) -> NamedTuple(
"Output", [("accuracy", float), ("precision", float), ("recall", float)]
):
import json
from collections import namedtuple
import joblib
import numpy as np
import wandb
from sklearn.ensemble import RandomForestClassifier # noqa: F401
from sklearn.metrics import accuracy_score, precision_score, recall_score
def add_wandb_visualization(run, mlpipeline_ui_metadata_path):
"""NOTE: To use this, you must modify your component to have an output called `mlpipeline_ui_metadata_path` AND call `wandb.init` yourself inside that component.
Example usage:
def my_component(..., mlpipeline_ui_metadata_path: OutputPath()):
import wandb
from wandb.integration.kfp.helpers import add_wandb_visualization
with wandb.init() as run:
add_wandb_visualization(run, mlpipeline_ui_metadata_path)
... # the rest of your code here
"""
def get_iframe_html(run):
return f'<iframe src="{run.url}?kfp=true" style="border:none;width:100%;height:100%;min-width:900px;min-height:600px;"></iframe>'
iframe_html = get_iframe_html(run)
metadata = {
"outputs": [
{"type": "markdown", "storage": "inline", "source": iframe_html}
]
}
with open(mlpipeline_ui_metadata_path, "w") as metadata_file:
json.dump(metadata, metadata_file)
with wandb.init() as run:
add_wandb_visualization(run, mlpipeline_ui_metadata_path)
with open(X_test_path, "rb") as f:
X_test = np.load(f) # noqa: N806
with open(y_test_path, "rb") as f:
y_test = np.load(f)
model = joblib.load(model_path)
preds = model.predict(X_test)
accuracy = accuracy_score(y_test, preds)
precision = precision_score(y_test, preds, average="micro")
recall = recall_score(y_test, preds, average="micro")
output = namedtuple("Output", ["accuracy", "precision", "recall"])
return output(accuracy, precision, recall) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 145 | 207 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
181 | add_wandb_visualization | def add_wandb_visualization(run, mlpipeline_ui_metadata_path):
"""NOTE: To use this, you must modify your component to have an output called `mlpipeline_ui_metadata_path` AND call `wandb.init` yourself inside that component.
Example usage:
def my_component(..., mlpipeline_ui_metadata_path: OutputPath()):
import wandb
from wandb.integration.kfp.helpers import add_wandb_visualization
with wandb.init() as run:
add_wandb_visualization(run, mlpipeline_ui_metadata_path)
... # the rest of your code here
"""
def get_iframe_html(run):
return f'<iframe src="{run.url}?kfp=true" style="border:none;width:100%;height:100%;min-width:900px;min-height:600px;"></iframe>'
iframe_html = get_iframe_html(run)
metadata = {
"outputs": [
{"type": "markdown", "storage": "inline", "source": iframe_html}
]
}
with open(mlpipeline_ui_metadata_path, "w") as metadata_file:
json.dump(metadata, metadata_file) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 162 | 188 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
182 | get_iframe_html | def get_iframe_html(run):
return f'<iframe src="{run.url}?kfp=true" style="border:none;width:100%;height:100%;min-width:900px;min-height:600px;"></iframe>' | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 177 | 178 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
183 | testing_pipeline | def testing_pipeline(seed: int):
conf = dsl.get_pipeline_conf()
conf.add_op_transformer(add_wandb_env_variables)
preprocess_data_task = preprocess_data(seed)
train_model_task = train_model(
preprocess_data_task.outputs["X_train"], preprocess_data_task.outputs["y_train"]
)
test_model_task = test_model( # noqa: F841
preprocess_data_task.outputs["X_test"],
preprocess_data_task.outputs["y_test"],
train_model_task.output,
) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-helper.py | 231 | 243 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
184 | add_wandb_env_variables | def add_wandb_env_variables(op):
env = {
"WANDB_API_KEY": os.getenv("WANDB_API_KEY"),
"WANDB_BASE_URL": os.getenv("WANDB_BASE_URL"),
"WANDB_KUBEFLOW_URL": os.getenv("WANDB_KUBEFLOW_URL"),
"WANDB_PROJECT": "wandb_kfp_integration_test",
}
for name, value in env.items():
op = op.add_env_variable(V1EnvVar(name, value))
return op | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-pytorch.py | 13 | 23 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
185 | setup_data | def setup_data(
train_dataset_path: components.OutputPath("tensor"), # noqa: F821
test_dataset_path: components.OutputPath("tensor"), # noqa: F821
):
import torch
from torchvision import datasets, transforms
transform = transforms.Compose(
[transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))]
)
train_dataset = datasets.FakeData(
size=2000, image_size=(1, 28, 28), num_classes=10, transform=transform
)
test_dataset = datasets.FakeData(
size=2000, image_size=(1, 28, 28), num_classes=10, transform=transform
)
torch.save(train_dataset, train_dataset_path)
torch.save(test_dataset, test_dataset_path) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-pytorch.py | 27 | 45 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
186 | setup_dataloaders | def setup_dataloaders(
train_dataset_path: components.InputPath("tensor"), # noqa: F821
test_dataset_path: components.InputPath("tensor"), # noqa: F821
train_dataloader_path: components.OutputPath("dataloader"), # noqa: F821
test_dataloader_path: components.OutputPath("dataloader"), # noqa: F821
batch_size: int = 32,
):
import torch
train_dataset = torch.load(train_dataset_path)
test_dataset = torch.load(test_dataset_path)
train_loader = torch.utils.data.DataLoader(
train_dataset,
batch_size=batch_size,
)
test_loader = torch.utils.data.DataLoader(
test_dataset,
batch_size=batch_size,
)
torch.save(train_loader, train_dataloader_path)
torch.save(test_loader, test_dataloader_path) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-pytorch.py | 49 | 71 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
187 | train_model | def train_model(
train_dataloader_path: components.InputPath("dataloader"), # noqa: F821
test_dataloader_path: components.InputPath("dataloader"), # noqa: F821
model_path: components.OutputPath("pytorch_model"), # noqa: F821
seed: int = 1337,
use_cuda: bool = False,
lr: float = 1.0,
gamma: float = 0.7,
epochs: int = 1,
log_interval: int = 10,
dry_run: bool = False,
save_model: bool = False,
):
import torch
import torch.nn as nn
import torch.nn.functional as F # noqa: N812
import torch.optim as optim
from torch.optim.lr_scheduler import StepLR
class Net(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10)
def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.dropout1(x)
x = torch.flatten(x, 1)
x = self.fc1(x)
x = F.relu(x)
x = self.dropout2(x)
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output
def train(model, device, train_loader, optimizer, epoch, log_interval, dry_run):
model.train()
for batch_idx, (data, target) in enumerate(train_loader):
data, target = data.to(device), target.to(device)
optimizer.zero_grad()
output = model(data)
loss = F.nll_loss(output, target)
loss.backward()
optimizer.step()
if batch_idx % log_interval == 0:
wandb.log(
{"epoch": epoch, "step": batch_idx * len(data), "loss": loss.item()}
)
if dry_run:
break
def test(model, device, test_loader):
model.eval()
test_loss = 0
correct = 0
with torch.no_grad():
for data, target in test_loader:
data, target = data.to(device), target.to(device)
output = model(data)
test_loss += F.nll_loss(
output, target, reduction="sum"
).item() # sum up batch loss
pred = output.argmax(
dim=1, keepdim=True
) # get the index of the max log-probability
correct += pred.eq(target.view_as(pred)).sum().item()
test_loss /= len(test_loader.dataset)
wandb.log(
{"test_loss": test_loss, "accuracy": correct / len(test_loader.dataset)}
)
torch.manual_seed(seed)
train_loader = torch.load(train_dataloader_path)
test_loader = torch.load(test_dataloader_path)
device = torch.device("cuda" if use_cuda else "cpu")
model = Net()
model.to(device)
optimizer = optim.Adadelta(model.parameters(), lr=lr)
scheduler = StepLR(optimizer, step_size=1, gamma=gamma)
for epoch in range(1, epochs + 1):
train(
model,
device,
train_loader,
optimizer,
epoch,
log_interval,
dry_run,
)
test(model, device, test_loader)
scheduler.step()
if save_model:
torch.save(model.state_dict(), model_path) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-pytorch.py | 75 | 179 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
188 | __init__ | def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1)
self.dropout1 = nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5)
self.fc1 = nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-pytorch.py | 95 | 102 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
189 | forward | def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.conv2(x)
x = F.relu(x)
x = F.max_pool2d(x, 2)
x = self.dropout1(x)
x = torch.flatten(x, 1)
x = self.fc1(x)
x = F.relu(x)
x = self.dropout2(x)
x = self.fc2(x)
output = F.log_softmax(x, dim=1)
return output | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-pytorch.py | 104 | 117 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
190 | train | def train(model, device, train_loader, optimizer, epoch, log_interval, dry_run):
model.train()
for batch_idx, (data, target) in enumerate(train_loader):
data, target = data.to(device), target.to(device)
optimizer.zero_grad()
output = model(data)
loss = F.nll_loss(output, target)
loss.backward()
optimizer.step()
if batch_idx % log_interval == 0:
wandb.log(
{"epoch": epoch, "step": batch_idx * len(data), "loss": loss.item()}
)
if dry_run:
break | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-pytorch.py | 119 | 133 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
191 | test | def test(model, device, test_loader):
model.eval()
test_loss = 0
correct = 0
with torch.no_grad():
for data, target in test_loader:
data, target = data.to(device), target.to(device)
output = model(data)
test_loss += F.nll_loss(
output, target, reduction="sum"
).item() # sum up batch loss
pred = output.argmax(
dim=1, keepdim=True
) # get the index of the max log-probability
correct += pred.eq(target.view_as(pred)).sum().item()
test_loss /= len(test_loader.dataset)
wandb.log(
{"test_loss": test_loss, "accuracy": correct / len(test_loader.dataset)}
) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-pytorch.py | 135 | 154 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
192 | testing_pipeline | def testing_pipeline(seed, save_model):
conf = dsl.get_pipeline_conf()
conf.add_op_transformer(add_wandb_env_variables)
setup_data_task = setup_data()
setup_dataloaders_task = setup_dataloaders(
setup_data_task.outputs["train_dataset"],
setup_data_task.outputs["test_dataset"],
batch_size=32,
)
train_model_task = train_model( # noqa: F841
setup_dataloaders_task.outputs["train_dataloader"],
setup_dataloaders_task.outputs["test_dataloader"],
save_model=save_model,
) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-pytorch.py | 203 | 217 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
193 | wandb_probe_package | def wandb_probe_package():
if not os.environ.get("WB_PROBE_PACKAGE"):
return
s, o = subprocess.getstatusoutput("git rev-parse HEAD")
if s:
return
wandb_local = f"git+https://github.com/wandb/wandb.git@{o}#egg=wandb"
return wandb_local | python | tests/functional_tests/t0_main/kfp/wandb_probe.py | 5 | 12 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
194 | add_wandb_env_variables | def add_wandb_env_variables(op):
env = {
"WANDB_API_KEY": os.getenv("WANDB_API_KEY"),
"WANDB_BASE_URL": os.getenv("WANDB_BASE_URL"),
"WANDB_KUBEFLOW_URL": os.getenv("WANDB_KUBEFLOW_URL"),
"WANDB_PROJECT": "wandb_kfp_integration_test",
}
for name, value in env.items():
op = op.add_env_variable(V1EnvVar(name, value))
return op | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-sklearn.py | 13 | 23 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
195 | preprocess_data | def preprocess_data(
X_train_path: components.OutputPath("np_array"), # noqa: F821,N803
X_test_path: components.OutputPath("np_array"), # noqa: F821,N803
y_train_path: components.OutputPath("np_array"), # noqa: F821
y_test_path: components.OutputPath("np_array"), # noqa: F821
seed: int = 1337,
):
import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split
X, y = datasets.load_iris(return_X_y=True) # noqa: N806
X_train, X_test, y_train, y_test = train_test_split( # noqa: N806
X, y, test_size=0.2, random_state=seed
)
with open(X_train_path, "wb") as f:
np.save(f, X_train)
with open(y_train_path, "wb") as f:
np.save(f, y_train)
with open(X_test_path, "wb") as f:
np.save(f, X_test)
with open(y_test_path, "wb") as f:
np.save(f, y_test) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-sklearn.py | 27 | 53 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
196 | train_model | def train_model(
X_train_path: components.InputPath("np_array"), # noqa: F821,N803
y_train_path: components.InputPath("np_array"), # noqa: F821
model_path: components.OutputPath("sklearn_model"), # noqa: F821
):
import joblib
import numpy as np
from sklearn.ensemble import RandomForestClassifier
with open(X_train_path, "rb") as f:
X_train = np.load(f) # noqa: N806
with open(y_train_path, "rb") as f:
y_train = np.load(f)
model = RandomForestClassifier()
model.fit(X_train, y_train)
joblib.dump(model, model_path) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-sklearn.py | 57 | 75 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
197 | test_model | def test_model(
X_test_path: components.InputPath("np_array"), # noqa: F821,N803
y_test_path: components.InputPath("np_array"), # noqa: F821
model_path: components.InputPath("sklearn_model"), # noqa: F821
) -> NamedTuple(
"Output", [("accuracy", float), ("precision", float), ("recall", float)]
):
from collections import namedtuple
import joblib
import numpy as np
from sklearn.ensemble import RandomForestClassifier # noqa: F401
from sklearn.metrics import accuracy_score, precision_score, recall_score
with open(X_test_path, "rb") as f:
X_test = np.load(f) # noqa: N806
with open(y_test_path, "rb") as f:
y_test = np.load(f)
model = joblib.load(model_path)
preds = model.predict(X_test)
accuracy = accuracy_score(y_test, preds)
precision = precision_score(y_test, preds, average="micro")
recall = recall_score(y_test, preds, average="micro")
output = namedtuple("Output", ["accuracy", "precision", "recall"])
return output(accuracy, precision, recall) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-sklearn.py | 79 | 107 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
198 | testing_pipeline | def testing_pipeline(seed: int):
conf = dsl.get_pipeline_conf()
conf.add_op_transformer(add_wandb_env_variables)
preprocess_data_task = preprocess_data(seed)
train_model_task = train_model(
preprocess_data_task.outputs["X_train"], preprocess_data_task.outputs["y_train"]
)
test_model_task = test_model( # noqa: F841
preprocess_data_task.outputs["X_test"],
preprocess_data_task.outputs["y_test"],
train_model_task.output,
) | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-sklearn.py | 131 | 143 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
199 | add_wandb_env_variables | def add_wandb_env_variables(op):
env = {
"WANDB_API_KEY": os.getenv("WANDB_API_KEY"),
"WANDB_BASE_URL": os.getenv("WANDB_BASE_URL"),
"WANDB_KUBEFLOW_URL": os.getenv("WANDB_KUBEFLOW_URL"),
"WANDB_PROJECT": "wandb_kfp_integration_test",
}
for name, value in env.items():
op = op.add_env_variable(V1EnvVar(name, value))
return op | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-simple.py | 12 | 22 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
200 | add | def add(a: float, b: float) -> float:
return a + b | python | tests/functional_tests/t0_main/kfp/kfp-pipeline-simple.py | 26 | 27 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.