winglian commited on
Commit
9ff4e9a
·
verified ·
1 Parent(s): c5d7d6f

Install cut-cross-entropy and log CUDA memory

Browse files
__pycache__/local_training_common.cpython-312.pyc CHANGED
Binary files a/__pycache__/local_training_common.cpython-312.pyc and b/__pycache__/local_training_common.cpython-312.pyc differ
 
__pycache__/train_grpo_local.cpython-312.pyc CHANGED
Binary files a/__pycache__/train_grpo_local.cpython-312.pyc and b/__pycache__/train_grpo_local.cpython-312.pyc differ
 
__pycache__/train_sft_local.cpython-312.pyc CHANGED
Binary files a/__pycache__/train_sft_local.cpython-312.pyc and b/__pycache__/train_sft_local.cpython-312.pyc differ
 
__pycache__/zerogpu_tinker_service.cpython-312.pyc CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:39882bb35d1044aee21117e4e84b63b50fe8a7c12e427d42f3a897a4e36701d7
3
- size 102030
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:786870ce3b5415a2fa92c73c0e1e54ffc685353d2e06afbad45b5c778778ab0d
3
+ size 121790
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  transformers @ git+https://github.com/huggingface/transformers.git
2
  hatchery-core[zerogpu] @ git+https://github.com/axolotl-ai-cloud/hatchery-core.git@914c893
 
3
  torchao
4
  dflash @ git+https://github.com/winglian/dflash.git@904b558
5
  flash-linear-attention
 
1
  transformers @ git+https://github.com/huggingface/transformers.git
2
  hatchery-core[zerogpu] @ git+https://github.com/axolotl-ai-cloud/hatchery-core.git@914c893
3
+ cut-cross-entropy @ git+https://github.com/axolotl-ai-cloud/ml-cross-entropy.git
4
  torchao
5
  dflash @ git+https://github.com/winglian/dflash.git@904b558
6
  flash-linear-attention
train_grpo_local.py CHANGED
@@ -344,6 +344,13 @@ def log_rollout(wandb_run: Any | None, record: dict[str, Any]) -> None:
344
  "rollout/generated_tokens_server": profile.get("generated_tokens"),
345
  }
346
  )
 
 
 
 
 
 
 
347
  wandb_run.log(payload)
348
 
349
 
@@ -390,6 +397,13 @@ def log_train_step(wandb_run: Any | None, record: Any) -> None:
390
  "train/cuda_synchronize_ms": phase_duration_ms(profile, "cuda_synchronize"),
391
  }
392
  )
 
 
 
 
 
 
 
393
  collate_ms = 0.0
394
  collate_found = False
395
  fwd_bwd_ms = 0.0
 
344
  "rollout/generated_tokens_server": profile.get("generated_tokens"),
345
  }
346
  )
347
+ for key in (
348
+ "cuda_memory_allocated_bytes",
349
+ "cuda_memory_reserved_bytes",
350
+ "cuda_max_memory_allocated_bytes",
351
+ "cuda_max_memory_reserved_bytes",
352
+ ):
353
+ payload[f"rollout/{key}"] = profile.get(key)
354
  wandb_run.log(payload)
355
 
356
 
 
397
  "train/cuda_synchronize_ms": phase_duration_ms(profile, "cuda_synchronize"),
398
  }
399
  )
400
+ for key in (
401
+ "cuda_memory_allocated_bytes",
402
+ "cuda_memory_reserved_bytes",
403
+ "cuda_max_memory_allocated_bytes",
404
+ "cuda_max_memory_reserved_bytes",
405
+ ):
406
+ payload[f"train/{key}"] = profile.get(key)
407
  collate_ms = 0.0
408
  collate_found = False
409
  fwd_bwd_ms = 0.0
train_sft_local.py CHANGED
@@ -148,6 +148,13 @@ def log_train_step(wandb_run: Any | None, record: Any) -> None:
148
  "train/cuda_synchronize_ms": phase_duration_ms(profile, "cuda_synchronize"),
149
  }
150
  )
 
 
 
 
 
 
 
151
  collate_ms = 0.0
152
  collate_found = False
153
  fwd_bwd_ms = 0.0
 
148
  "train/cuda_synchronize_ms": phase_duration_ms(profile, "cuda_synchronize"),
149
  }
150
  )
151
+ for key in (
152
+ "cuda_memory_allocated_bytes",
153
+ "cuda_memory_reserved_bytes",
154
+ "cuda_max_memory_allocated_bytes",
155
+ "cuda_max_memory_reserved_bytes",
156
+ ):
157
+ payload[f"train/{key}"] = profile.get(key)
158
  collate_ms = 0.0
159
  collate_found = False
160
  fwd_bwd_ms = 0.0
zerogpu_tinker_service.py CHANGED
@@ -526,6 +526,11 @@ class _Profiler:
526
  self.context = {key: value for key, value in context.items() if value is not None}
527
  self.started = time.monotonic()
528
  self.phases: list[dict[str, Any]] = []
 
 
 
 
 
529
 
530
  @contextmanager
531
  def phase(self, name: str, **fields: Any):
@@ -545,13 +550,28 @@ class _Profiler:
545
  _log_event("zerogpu_profile", **self.snapshot(**fields))
546
 
547
  def snapshot(self, **fields: Any) -> dict[str, Any]:
548
- return {
549
  "operation": self.operation,
550
  "duration_ms": round((time.monotonic() - self.started) * 1000, 2),
551
  "phases": self.phases,
552
  **self.context,
553
  **{key: value for key, value in fields.items() if value is not None},
554
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555
 
556
 
557
  def _response_context(result: Any) -> dict[str, Any]:
@@ -569,6 +589,18 @@ def _response_context(result: Any) -> dict[str, Any]:
569
  return context
570
 
571
 
 
 
 
 
 
 
 
 
 
 
 
 
572
  def _write_session_metadata(session: ServiceSession) -> None:
573
  path = _metadata_path(session.model_id)
574
  path.parent.mkdir(parents=True, exist_ok=True)
@@ -1866,6 +1898,7 @@ def build_tinker_api() -> FastAPI:
1866
  "max_rank": _supported_rank(),
1867
  "futures_api": True,
1868
  "sdk_compat_version": "tinker-0.x",
 
1869
  "zero_gpu": True,
1870
  "speculative_decoding": {
1871
  "backend": "dflash",
@@ -2036,6 +2069,7 @@ def build_space_app() -> Any:
2036
  "max_rank": _supported_rank(),
2037
  "futures_api": True,
2038
  "sdk_compat_version": "tinker-0.x",
 
2039
  "zero_gpu": True,
2040
  "speculative_decoding": {
2041
  "backend": "dflash",
 
526
  self.context = {key: value for key, value in context.items() if value is not None}
527
  self.started = time.monotonic()
528
  self.phases: list[dict[str, Any]] = []
529
+ if torch.cuda.is_available():
530
+ try:
531
+ torch.cuda.reset_peak_memory_stats()
532
+ except Exception:
533
+ pass
534
 
535
  @contextmanager
536
  def phase(self, name: str, **fields: Any):
 
550
  _log_event("zerogpu_profile", **self.snapshot(**fields))
551
 
552
  def snapshot(self, **fields: Any) -> dict[str, Any]:
553
+ payload = {
554
  "operation": self.operation,
555
  "duration_ms": round((time.monotonic() - self.started) * 1000, 2),
556
  "phases": self.phases,
557
  **self.context,
558
  **{key: value for key, value in fields.items() if value is not None},
559
  }
560
+ if torch.cuda.is_available():
561
+ try:
562
+ payload.update(
563
+ {
564
+ "cuda_memory_allocated_bytes": int(torch.cuda.memory_allocated()),
565
+ "cuda_memory_reserved_bytes": int(torch.cuda.memory_reserved()),
566
+ "cuda_max_memory_allocated_bytes": int(
567
+ torch.cuda.max_memory_allocated()
568
+ ),
569
+ "cuda_max_memory_reserved_bytes": int(torch.cuda.max_memory_reserved()),
570
+ }
571
+ )
572
+ except Exception:
573
+ pass
574
+ return payload
575
 
576
 
577
  def _response_context(result: Any) -> dict[str, Any]:
 
589
  return context
590
 
591
 
592
+ def _fused_ce_kernels_available() -> list[str]:
593
+ from hatchery.core.fused_losses import _try_import_cce, _try_import_liger
594
+
595
+ kernels: list[str] = []
596
+ if _try_import_cce() is not None:
597
+ kernels.append("cce")
598
+ if _try_import_liger() is not None:
599
+ kernels.append("liger")
600
+ kernels.append("chunked")
601
+ return kernels
602
+
603
+
604
  def _write_session_metadata(session: ServiceSession) -> None:
605
  path = _metadata_path(session.model_id)
606
  path.parent.mkdir(parents=True, exist_ok=True)
 
1898
  "max_rank": _supported_rank(),
1899
  "futures_api": True,
1900
  "sdk_compat_version": "tinker-0.x",
1901
+ "fused_ce_kernels_available": _fused_ce_kernels_available(),
1902
  "zero_gpu": True,
1903
  "speculative_decoding": {
1904
  "backend": "dflash",
 
2069
  "max_rank": _supported_rank(),
2070
  "futures_api": True,
2071
  "sdk_compat_version": "tinker-0.x",
2072
+ "fused_ce_kernels_available": _fused_ce_kernels_available(),
2073
  "zero_gpu": True,
2074
  "speculative_decoding": {
2075
  "backend": "dflash",