[Midnightbsd-cvs] [MidnightBSD/mports] 9f1f9b: ai/pytorch: add optional distributed training supp...

Lucas Holt noreply at github.com
Mon Sep 7 11:18:32 EDT 2026


  Branch: refs/heads/master
  Home:   https://github.com/MidnightBSD/mports
  Commit: 9f1f9b533d28a49ad30901a3fd41567d2c0ea9b9
      https://github.com/MidnightBSD/mports/commit/9f1f9b533d28a49ad30901a3fd41567d2c0ea9b9
  Author: Lucas Holt <luke at foolishgames.com>
  Date:   2026-09-07 (Mon, 07 Sep 2026)

  Changed paths:
    M ai/pytorch/Makefile
    A ai/pytorch/files/patch-third__party_tensorpipe_tensorpipe_common_system.cc
    M ai/pytorch/pkg-plist

  Log Message:
  -----------
  ai/pytorch: add optional distributed training support (#852)

Adds a `DISTRIBUTED` option, **off by default**, that enables
`USE_DISTRIBUTED`
and builds the gloo, MPI and tensorpipe backends.

Follow-up to #851, which asked whether the libuv patch it carried was
dead
weight. It isn't — this is what exercises it.

## Why it was off

Upstream disables `USE_DISTRIBUTED` on every platform that isn't Linux
or
Windows (`CMakeLists.txt:200` — *"not tested and likely won't work
without
additional changes"*), and the FreeBSD port leaves it that way. Two
things were
needed to make it build here.

### 1. libuv (patch already in tree)

`CMAKE_SYSTEM_NAME` is `"MidnightBSD"`, so libuv's `MATCHES "FreeBSD"`
guards
never fire and it gets **no BSD sources at all**. The patch from #851
fixes
that; with it, the build compiles `kqueue.c`, `freebsd.c`,
`bsd-ifaddrs.c`,
`bsd-proctitle.c`, `posix-hrtime.c` and `random-getrandom.c`.

libuv is required here rather than optional. gloo's other transport is
tcp,
which is Linux-only (it uses `epoll(2)`, and gloo gates it on
`CMAKE_SYSTEM_NAME STREQUAL "Linux"`), so without libuv gloo would build
with
no transport at all. `USE_LIBUV` is therefore tied to the same knob
instead of
being separately selectable.

### 2. tensorpipe (new patch)

`tensorpipe/common/system.cc` defines `getBootIDInternal()` only for
`__APPLE__` and `__linux__`, so it's undeclared here. The new patch adds
a
`__FreeBSD__` branch. FreeBSD and MidnightBSD have no per-boot UUID, so
it
combines the stable `kern.hostuuid` with `kern.boottime` — which matches
what
tensorpipe uses the boot ID for: deciding whether two processes share a
machine
*and a boot*, for shared-memory channel eligibility.

## Footprint

The option adds **26 installed files**, all tensorpipe: 22 headers,
`libtensorpipe.a`, `libtensorpipe_uv.a`, and two cmake config files.
gloo and
libuv install nothing — they link statically into `libtorch_cpu`. The
plist is
a pure superset, so the 26 entries are simply gated on
`%%DISTRIBUTED%%`.

## Testing

On MidnightBSD 4.2 amd64, with the option enabled:

- all 13 patches apply cleanly against a fresh extract
- `bmake build` — completes, 100%, zero errors
- `libtorch_cpu.so` exports **782** distributed symbols, including
  `ProcessGroupGloo`, `ProcessGroupMPI` and `TensorPipeAgent`
- `bmake fake` / `bmake package` — `pytorch-2.13.0_1.mport`
- `%%DISTRIBUTED%%` verified in both states: `"@comment "` by default,
`""`
  with the option set

## Caveat

**Only the build and link are verified.** Distributed training has not
been
exercised at runtime — that needs multiple processes or hosts — and the
libuv
gloo transport is far less travelled than the Linux tcp path. That's why
the
option defaults to off.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01XkHF8bn8Ehit2aSoWjCshm

## Summary by Sourcery

Add opt-in distributed training support to the PyTorch port for
MidnightBSD.

New Features:
- Add an optional, disabled-by-default distributed training
configuration for PyTorch using Gloo, MPI, and TensorPipe backends.

Bug Fixes:
- Enable TensorPipe boot identification on FreeBSD-compatible systems so
distributed builds compile successfully.

Enhancements:
- Tie libuv support to distributed training to provide Gloo transport
support on non-Linux platforms.

Chores:
- Update the package file list for distributed-training artifacts.

Signed-off-by: Lucas Holt <luke at foolishgames.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply at anthropic.com>



To unsubscribe from these emails, change your notification settings at https://github.com/MidnightBSD/mports/settings/notifications



More information about the Midnightbsd-cvs mailing list