Scaling DINOv2 pretraining for histopathology WSI on AMD Instinct MI355X GPUs#
Foundation models are reshaping computational pathology. Instead of training a separate network for every diagnostic task, teams pretrain one large vision model on unlabeled tissue images and adapt it to downstream tasks such as tissue classification and segmentation. Expert annotations are scarce and expensive, so self-supervised pretraining is especially valuable here. It is also compute-intensive: the training data runs to millions of image patches, so GPU throughput and multi-GPU scaling determine how quickly a team can iterate on its models.
Bayer’s production DINOv2 histopathology recipe runs on AMD Instinct with minimal changes. DINOv2 learns general-purpose visual representations through self-supervised pretraining, making it a strong fit for whole-slide imaging (WSI), where gigapixel pathology scans are broken into millions of smaller patches before training. Bayer’s fork extends DINOv2 with histopathology-specific data loading, augmentations, and evaluation. For this study, we focused our benchmarks on ViT-L/14. In this blog, we show how to run the recipe on AMD Instinct MI355X GPUs using the official ROCm PyTorch image, an xformers build for gfx950, and the same FSDP training path Bayer uses in production, with no changes to the training code.
All experiments below use eight-GPU MI355X nodes unless noted otherwise.
Setup: ROCm Container and Dependencies#
Start from the official rocm/pytorch image, which provides the ROCm and PyTorch stack. We used ROCm 7.2.2 with PyTorch 2.10 on MI355X (gfx950).
Platform |
GPU architecture |
ROCm stack |
|---|---|---|
MI355X |
gfx950 |
ROCm 7.2.2 |
We adapted Bayer’s original install instructions for ROCm with three changes:
Preserve the validated image stack. The official ROCm PyTorch image already includes compatible builds of PyTorch and its accelerator runtime. We install selected packages such as
mmcvandtimmwith--no-depsto prevent package resolution from replacing that validated stack with different platform-specific builds. Thepyproject.tomlin the Dockerfile below comes from Bayer’s DINOv2 fork.Build xformers for gfx950. See the next section. At the time of this work, no pre-built gfx950 wheel was available on the PyTorch ROCm index.
Match CPU allocation to GPU count. Under-provisioned CPUs caused inconsistent iteration times and GPU underutilization. Setting
cpus-per-gpu=24for eight-GPU jobs (and proportionally for smaller jobs) stabilized throughput.
Docker Image for MI355X#
Our primary image uses ROCm 7.2.2 and the gfx950 xformers wheel built from source (see Dockerfile.rocm722-xformers):
FROM rocm/pytorch:rocm7.2.2_ubuntu24.04_py3.12_pytorch_release_2.10.0
WORKDIR /workspace
COPY pyproject.toml /workspace
RUN pip install -e .
RUN pip install timm torchmetrics lightning-utilities --no-deps
# Install gfx950 xformers wheel (built separately; see section below)
COPY wheels/ /tmp/wheels/
RUN pip install --no-deps /tmp/wheels/xformers-*.whl && rm -rf /tmp/wheels
Build and launch:
docker build -f src/docker/Dockerfile.rocm722-xformers -t dinov2-rocm722:xformers .
docker run -it --network=host --device=/dev/kfd --device=/dev/dri \
--group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
-v /path/to/patches:/workspace/data \
-v /path/to/output:/workspace/output \
dinov2-rocm722:xformers
The training command writes checkpoints and other outputs to /workspace/output. Mount that path to a host directory to preserve the outputs after the container exits.
Building xformers for MI355X (gfx950)#
One build step gives you the same xformers experience on MI355X as on other architectures (for MI300X - gfx942, a pre-built xformers wheel from the PyTorch ROCm index is sufficient).
DINOv2’s default attention path uses xformers memory_efficient_attention via MemEffAttention. At the time of this work, no pre-built wheel on the PyTorch ROCm index included gfx950 Composable Kernel dispatch entries. We provide the build recipe below so developers can reproduce a working wheel and run DINOv2 with xformers on MI355X without changing the training code.
This follows the standard xformers build instructions, with one ROCm-specific addition: set PYTORCH_ROCM_ARCH=gfx950 so the wheel targets MI355X.
Build on a GPU node inside the target container:
git clone --recursive -b v0.0.35 https://github.com/facebookresearch/xformers.git /tmp/xformers
cd /tmp/xformers
PYTORCH_ROCM_ARCH=gfx950 USE_ROCM=1 ROCM_PATH=/opt/rocm MAX_JOBS=16 \
pip wheel . --no-build-isolation --no-deps -w wheels/
pip install --no-deps wheels/xformers-*.whl
Before building the Docker image, copy the resulting wheel into a wheels/ directory in the Docker build context. The Dockerfile copies that build-context directory to /tmp/wheels/ inside the image for installation and removes it afterward. Docker cannot copy a host file directly from /tmp/wheels/ because files used by COPY must be inside the build context.
Important notes:
Use
USE_ROCM=1so the ROCm build path is selected.The wheel must be built against the exact PyTorch version in the container (e.g., 2.10.0+rocm7.2.2).
Import checks during
docker builddo not exercise GPU kernels; run a short training smoke test after the image is built.
Once this wheel is in your image, DINOv2 trains with xformers attention out of the box, with no code changes needed.
Getting Started with Training#
Once the container is running and patches are mounted, verify the GPU and xformers:
import torch
import xformers
from xformers.ops import memory_efficient_attention
print(torch.cuda.get_device_name(0))
print("xformers", xformers.__version__)
Launch single-node training on eight MI355X GPUs with a ViT-L/14 config:
export PYTHONPATH=/workspace
torchrun --nproc_per_node=8 dinov2/train/train.py \
--config-file dinov2/configs/train/vitl14.yaml \
--output-dir /workspace/output \
train.dataset_path=HistoPatchDataset:split=train:root=/workspace/data
We added PyTorch profiling to the training script, controlled via environment variables:
export DINOV2_PROFILE=1
export DINOV2_PROFILE_SCHEDULE="1,3,6,1" # wait,warmup,active,repeat
export DINOV2_PROFILE_MEMORY=1 # optional memory timeline
Attention Backends#
xformers delivers the best end-to-end throughput for DINOv2 on MI355X.
The Bayer DINOv2 repository was updated between the attention-backend comparison and the scaling experiments. Because the experiments used different repository revisions, their absolute performance results are not directly comparable.
We compared attention backends on MI355X with ViT-L/14 and ROCm 7. Figure 1 and the table below show xformers against SDPA efficient at the batch sizes tested with both backends:
Fig. 1. Training throughput of DINOv2 ViT-L/14 on one eight-GPU MI355X node (batch size per GPU) with xformers and PyTorch SDPA efficient attention. xformers is faster at every batch size measured with both backends.#
Attention |
Batch size |
s/iteration |
Samples/s |
|---|---|---|---|
xformers |
64 |
0.27 |
1,896 |
xformers |
160 |
0.58 |
2,207 |
SDPA efficient |
64 |
0.30 |
1,724 |
SDPA efficient |
160 |
0.64 |
2,000 |
At every batch size where both backends were measured, xformers achieved higher throughput (e.g., up to 2,207 samples/s vs. 2,000 for SDPA efficient at batch size 160). Throughput improves with batch size even though s/iteration increases because larger batches keep GPUs better utilized.
We also briefly evaluated SDPA flash, AITER / FA v3, and manual attention in profiling runs. At large batch sizes, xformers remained the best end-to-end choice for this workload.
Profile before tuning kernels. At the default batch size of 16, training is CPU-bound. GPUs wait on data loading, augmentation, and DINO teacher-student coordination rather than attention. Switching attention backends made little difference in wall-clock time at that batch size. The batch-size sweep above shows the transition to a GPU-bound regime as batch size increases.
Actionable order of operations:
Increase batch size (within memory limits) to get GPUs off the CPU bottleneck.
Use xformers as the attention backend at production batch sizes.
Tune individual kernels only after profiling confirms the workload is GPU-bound.
Scaling Results#
MI355X scales efficiently across GPUs and nodes. FSDP is the right choice for distributed training; see below.
FSDP Versus DDP#
DINOv2 ships with native Fully Sharded Data Parallel (FSDP) support. We also implemented a Distributed Data Parallel (DDP) code path with configurable bucket sizes and gradient communication overlap. On a single eight-GPU MI355X node at the same global batch size, FSDP consistently achieved lower total training time than DDP. This matches the DINOv2 paper’s observation that their sharding strategy can outperform plain DDP due to faster mixed-precision communication patterns. Multi-node jobs used hybrid FSDP (HYBRID_SHARD, which shards within a node and replicates across nodes) as a middle ground between full sharding and DDP.
GPU Scaling#
Each configuration was run on MI355X with ViT-L/14 and xformers. Values are averaged across replicates. Scaling efficiency is computed as current samples/s ÷ (single-GPU samples/s \(\times\) GPU count) \(\times\) 100.
Strong scaling (global batch size fixed at 320). Figure 2 shows how throughput increases with GPU count while falling increasingly below ideal linear scaling:
Fig. 2. Strong-scaling throughput with the global batch fixed at 320 (ViT-L/14, xformers). The dashed line shows ideal linear scaling from the single-GPU result. The gain flattens beyond 8 GPUs as the per-GPU batch shrinks to 20.#
GPUs |
Batch size / GPU |
s/it |
Samples/s |
Scaling efficiency |
|---|---|---|---|---|
1 |
320 |
1.0746 |
297.8 |
100.0% |
2 |
160 |
0.6873 |
465.6 |
78.2% |
4 |
80 |
0.3673 |
871.2 |
73.1% |
8 |
40 |
0.2452 |
1,305.0 |
54.8% |
16 |
20 |
0.2296 |
1,393.5 |
29.3% |
Strong-scaling efficiency drops as GPU count increases because the global batch stays fixed at 320 while the batch per GPU shrinks. Each GPU then does less compute per step, but gradient synchronization and DINOv2’s per-step overhead do not shrink at the same rate.
Weak scaling (batch size fixed at 320 per GPU):
At 16 GPUs across two nodes, the updated weak-scaling run reaches 4,078.9 samples/s, or 85.6% scaling efficiency at 254.9 samples/s per GPU. Correct RCCL configuration is essential for multi-node jobs to perform reliably; see below.
These values are from MI355X ViT-L/14 runs using HYBRID_SHARD and xformers. Throughput is calculated from the reported training step time over 1,000 iterations. Figure 3 shows that throughput remains close to ideal as GPUs are added:
Fig. 3. Weak-scaling throughput with the batch fixed at 320 per GPU (ViT-L/14, xformers, HYBRID_SHARD). The dashed line shows ideal linear scaling from the single-GPU result. Throughput stays close to ideal from 1 GPU to 16 GPUs across two nodes.#
Nodes |
Total GPUs |
Global batch |
s/it |
Samples/s |
Samples/s per GPU |
Scaling efficiency |
|---|---|---|---|---|---|---|
1 |
1 |
320 |
1.0746 |
297.8 |
297.8 |
100.0% |
1 |
2 |
640 |
1.1856 |
539.8 |
269.9 |
90.6% |
1 |
4 |
1,280 |
1.1963 |
1,070.0 |
267.5 |
89.8% |
1 |
8 |
2,560 |
1.2497 |
2,048.5 |
256.1 |
86.0% |
2 |
16 |
5,120 |
1.2553 |
4,078.9 |
254.9 |
85.6% |
Multi-Node RCCL Configuration#
Multi-node jobs used torchrun with the c10d rendezvous backend, one Slurm task per node, and the ROCm Communication Collectives Library (RCCL) over Remote Direct Memory Access (RDMA). Our test environment used an AMD Pensando AI Network Interface Card (AINIC) and required the following environment variables for inter-node collective communication over RDMA:
# ANP plugin for AMD Pensando AINIC fabric
export NCCL_NET_PLUGIN=librccl-anp.so
# RDMA-capable network interface (find yours with: ibdev2netdev or ip link)
export NCCL_SOCKET_IFNAME=<your-rdma-interface>
export GLOO_SOCKET_IFNAME=<your-rdma-interface>
# GID index 1 selects the RoCEv2 GID entry on Pensando AINICs
export NCCL_IB_GID_INDEX=1
export NCCL_IB_ROUTABLE_FLID_GID_INDEX=1
# Pensando AINICs use IPv6 GIDs; set your cluster's ULA or global unicast prefix
export NCCL_IB_ADDR_FAMILY=AF_INET6
export NCCL_IB_ADDR_RANGE=<your-ipv6-subnet>/48 # e.g. fdXX:XXXX:XXXX::/48
# Let NCCL choose the best protocol automatically
export NCCL_PROTO=auto
For Docker jobs, forward all of these into the container with -e flags. The container launcher must also pass /dev/infiniband/* devices for direct access to the AINIC fabric. Incorrect fabric settings caused jobs to hang at rendezvous or fall back to slow socket transport.
Upgrading from ROCm 7.1.1 to ROCm 7.2.2 added native gfx950 support and improved RCCL behavior on the AINIC fabric.
Summary#
In this blog, you explored how to run Bayer’s DINOv2 histopathology training recipe on AMD Instinct MI355X GPUs without modifying the training code. You learned how to build xformers for gfx950, configure the ROCm image and training output, choose an attention backend, and launch FSDP jobs across one or two nodes.
The MI355X’s large High Bandwidth Memory (HBM) capacity accommodates larger per-GPU batches, helping improve training throughput. The strong and weak scaling results show how the recipe behaves as GPU count increases and provide a practical starting point for production-scale training.
The next step in this study will be to extend these data-scaling experiments through a larger multi-node training run on AMD Instinct GPUs.
Additional Resources#
Path |
Description |
|---|---|
MI355X Dockerfile with ROCm 7.2.2 and a gfx950 xformers wheel |
Disclaimers#
The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions, and typographical errors. The information contained herein is subject to change and may be rendered inaccurate for many reasons, including but not limited to product and roadmap changes, component and motherboard version changes, new model and/or product releases, product differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. Any computer system has risks of security vulnerabilities that cannot be completely prevented or mitigated. AMD assumes no obligation to update or otherwise correct or revise this information. However, AMD reserves the right to revise this information and to make changes from time to time to the content hereof without obligation of AMD to notify any person of such revisions or changes. THIS INFORMATION IS PROVIDED ‘AS IS.” AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE CONTENTS HEREOF AND ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS, OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION. AMD SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT WILL AMD BE LIABLE TO ANY PERSON FOR ANY RELIANCE, DIRECT, INDIRECT, SPECIAL, OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. AMD, the AMD Arrow logo, AMD Instinct, ROCm, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies. © 2026 Advanced Micro Devices, Inc. All rights reserved.