trainfabric 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.cjs +33 -16
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -8113,8 +8113,16 @@ var BillingClient = class extends ResourceClient {
8113
8113
  getSummary() {
8114
8114
  return this.requestGet("/v1/billing/summary");
8115
8115
  }
8116
- getUsage(unit) {
8117
- return this.requestGet(`/v1/billing/usage${unit ? `?unit=${unit}` : ""}`);
8116
+ getUsage(unit, runId) {
8117
+ const params = new URLSearchParams();
8118
+ if (unit) {
8119
+ params.set("unit", unit);
8120
+ }
8121
+ if (runId) {
8122
+ params.set("runId", runId);
8123
+ }
8124
+ const query = params.toString();
8125
+ return this.requestGet(`/v1/billing/usage${query ? `?${query}` : ""}`);
8118
8126
  }
8119
8127
  listInvoices() {
8120
8128
  return this.requestGet("/v1/billing/invoices");
@@ -8379,6 +8387,9 @@ var RunHandle = class {
8379
8387
  this.client = client;
8380
8388
  this.snapshot = snapshot;
8381
8389
  }
8390
+ isTerminal() {
8391
+ return ["completed", "failed", "canceled", "terminated"].includes(this.snapshot.status);
8392
+ }
8382
8393
  on(event, listener) {
8383
8394
  if (!this.listeners.has(event)) {
8384
8395
  this.listeners.set(event, /* @__PURE__ */ new Set());
@@ -8422,7 +8433,7 @@ var RunHandle = class {
8422
8433
  this.abortController.abort();
8423
8434
  }
8424
8435
  ensureStreaming() {
8425
- if (this.streaming || !this.shouldStream) {
8436
+ if (this.streaming || !this.shouldStream || this.isTerminal()) {
8426
8437
  return;
8427
8438
  }
8428
8439
  this.streaming = true;
@@ -8458,7 +8469,7 @@ var RunHandle = class {
8458
8469
  }
8459
8470
  await new Promise((resolve) => setTimeout(resolve, 1e3));
8460
8471
  }
8461
- if (["completed", "failed", "canceled", "terminated"].includes(this.snapshot.status)) {
8472
+ if (this.isTerminal()) {
8462
8473
  break;
8463
8474
  }
8464
8475
  }
@@ -8799,11 +8810,16 @@ var import_node_fs = __toESM(require("node:fs"), 1);
8799
8810
  var import_node_os = __toESM(require("node:os"), 1);
8800
8811
  var import_node_path2 = __toESM(require("node:path"), 1);
8801
8812
  function collectRuntimeFiles(repoPath) {
8802
- const candidates = ["training.yaml", "train.runtime.yaml", "pyproject.toml", "requirements.txt", "environment.yml", "Dockerfile", "train.py"];
8813
+ const manifestFiles = /* @__PURE__ */ new Set(["training.yaml", "train.runtime.yaml", "pyproject.toml", "requirements.txt", "environment.yml", "Dockerfile"]);
8803
8814
  const ignoredDirectories = /* @__PURE__ */ new Set([".git", ".hg", ".svn", "node_modules", ".venv", "venv", "__pycache__", ".mypy_cache", ".pytest_cache", "dist", "build"]);
8804
8815
  const found = [];
8816
+ const maxFiles = 256;
8817
+ const maxFileBytes = 256 * 1024;
8818
+ function shouldIncludeFile(fileName) {
8819
+ return manifestFiles.has(fileName) || fileName.endsWith(".py");
8820
+ }
8805
8821
  function walk(currentPath) {
8806
- if (found.length >= 64) {
8822
+ if (found.length >= maxFiles) {
8807
8823
  return;
8808
8824
  }
8809
8825
  for (const entry of import_node_fs.default.readdirSync(currentPath, { withFileTypes: true })) {
@@ -8815,11 +8831,11 @@ function collectRuntimeFiles(repoPath) {
8815
8831
  }
8816
8832
  continue;
8817
8833
  }
8818
- if (!entry.isFile() || !candidates.includes(entry.name)) {
8834
+ if (!entry.isFile() || !shouldIncludeFile(entry.name)) {
8819
8835
  continue;
8820
8836
  }
8821
8837
  const stat = import_node_fs.default.statSync(absolute);
8822
- if (stat.size > 256 * 1024) {
8838
+ if (stat.size > maxFileBytes) {
8823
8839
  continue;
8824
8840
  }
8825
8841
  found.push({
@@ -8922,7 +8938,7 @@ function buildComputeSpec(options) {
8922
8938
 
8923
8939
  // src/index.ts
8924
8940
  var DEFAULT_TRAINFABRIC_API_URL2 = "https://api.trainfabric.com";
8925
- var CLI_VERSION = "0.1.15";
8941
+ var CLI_VERSION = "0.1.17";
8926
8942
  var CONFIG_DIR = import_node_path3.default.join(import_node_os2.default.homedir(), ".trainfabric");
8927
8943
  var CONFIG_PATH = import_node_path3.default.join(CONFIG_DIR, "config.json");
8928
8944
  var FALLBACK_SECRET_PATH = import_node_path3.default.join(CONFIG_DIR, "session.enc");
@@ -9340,16 +9356,17 @@ async function watchRun(runId, json = false, timeoutMs, pollMs) {
9340
9356
  });
9341
9357
  handle.on("metric", (event) => {
9342
9358
  const payload = event.payload;
9343
- console.log(
9344
- `[metric] step=${payload.step ?? "?"} loss=${payload.loss ?? "?"} evalLoss=${payload.evalLoss ?? "?"}`
9345
- );
9359
+ const evalLoss = payload.evalLoss === void 0 ? "" : ` evalLoss=${payload.evalLoss}`;
9360
+ console.log(`[metric] step=${payload.step ?? "?"} loss=${payload.loss ?? "?"}${evalLoss}`);
9346
9361
  });
9347
9362
  handle.on("checkpoint", (event) => {
9348
9363
  const payload = event.payload;
9349
9364
  console.log(`[checkpoint] count=${payload.checkpointCount ?? "?"} path=${payload.checkpointPath ?? ""}`);
9350
9365
  });
9351
- handle.on("completed", () => {
9352
- console.log("[completed]");
9366
+ handle.on("completed", (event) => {
9367
+ const payload = event.payload;
9368
+ const metrics = payload.metrics ? ` finalLoss=${payload.metrics.finalLoss ?? "?"} evalLoss=${payload.metrics.evalLoss ?? "?"}` : "";
9369
+ console.log(`[completed]${metrics}`);
9353
9370
  });
9354
9371
  handle.on("failed", (event) => {
9355
9372
  const payload = event.payload;
@@ -9622,8 +9639,8 @@ program2.command("deployments:get").argument("<deploymentId>").description("Fetc
9622
9639
  program2.command("billing:summary").description("Fetch billing summary").action(async () => {
9623
9640
  printJson(await createClient(loadConfig()).billing.getSummary());
9624
9641
  });
9625
- program2.command("billing:usage").option("--unit <unit>", "normalized_tflop_seconds, reserved_gpu_seconds, or usd").description("List billing usage records").action(async (options) => {
9626
- printJson(await createClient(loadConfig()).billing.getUsage(options.unit));
9642
+ program2.command("billing:usage").option("--unit <unit>", "normalized_tflop_seconds, reserved_gpu_seconds, or usd").option("--run <runId>", "filter usage records to one run").description("List billing usage records").action(async (options) => {
9643
+ printJson(await createClient(loadConfig()).billing.getUsage(options.unit, options.run));
9627
9644
  });
9628
9645
  program2.command("billing:invoices").description("List invoices").action(async () => {
9629
9646
  printJson(await createClient(loadConfig()).billing.listInvoices());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trainfabric",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "Trainfabric CLI for launching GPU training jobs on the hosted Trainfabric backend.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",