Repository: learning-at-home/hivemind (language: python)

Issue:
pydantic < 2.0.0 is starting to conflict with other dependencies
**Describe the bug**
The version constraint of pydantic < 2.0.0 is conflicting with other dependencies.

**To Reproduce**
You could try to install both `hivemind` and [horde-sdk](https://github.com/Haidra-Org/horde-sdk) with pip. It will fail with dependency conflicts. If you try to install `horde-sdk` in a venv, it breaks `hivemind`:
```
vtx-lab-1  |   File "/usr/local/lib/python3.10/dist-packages/hivemind/dht/schema.py", line 168, in __get_validators__
vtx-lab-1  |     yield from super().__get_validators__()
vtx-lab-1  | AttributeError: 'super' object has no attribute '__get_validators__'
```

**Note**
At some point, I may attempt the fix myself. The problem is, I've never used pydantic, and I don't know what kind of cascading effects it may have on hivemind's dependent packages. For now, I'm stuck - and I would definitely appreciate a fix from someone else if possible.

**Environment**
* python 3.10.12
* hivemind 1.1.5 (as required by [hivemind-lightning](https://github.com/Lightning-Universe/lightning-Hivemind/blob/main/requirements.txt))
* output from pytorch [environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py):
```
PyTorch version: 2.1.1+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: 14.0.0-1ubuntu1.1
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.5.9-arch2-1-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.2.140
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1070
Nvidia driver version: 535.113.01
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Address sizes:                      39 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             8
On-line CPU(s) list:                0-7
Vendor ID:                          GenuineIntel
Model name:                         Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
CPU family:                         6
Model:                              60
Thread(s) per core:                 2
Core(s) per socket:                 4
Socket(s):                          1
Stepping:                           3
CPU max MHz:                        4400.0000
CPU min MHz:                        800.0000
BogoMIPS:                           7998.77
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
L1d cache:                          128 KiB (4 instances)
L1i cache:                          128 KiB (4 instances)
L2 cache:                           1 MiB (4 instances)
L3 cache:                           8 MiB (1 instance)
NUMA node(s):                       1
NUMA node0 CPU(s):                  0-7
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit:        KVM: Mitigation: VMX unsupported
Vulnerability L1tf:                 Mitigation; PTE Inversion
Vulnerability Mds:                  Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:             Mitigation; PTI
Vulnerability Mmio stale data:      Unknown: No mitigations
Vulnerability Retbleed:             Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:                Mitigation; Microcode
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] numpy==1.26.2
[pip3] onnxruntime==1.16.2
[pip3] pytorch-lightning==2.1.2
[pip3] pytorch_optimizer==2.12.0
[pip3] torch==2.1.1
[pip3] torchmetrics==1.2.0
[pip3] torchvision==0.16.1
[pip3] triton==2.1.0
[conda] Could not collect
```



Discussion / hints:
Hello :)
Any chance to get pydantic 2+ working with Hivemind any time soon?

EDIT: pydantic < 2 is breaking other packages like LiteLLM I'm trying to use Petals with.

Fix patch:
diff --git a/examples/albert/utils.py b/examples/albert/utils.py
index 4d5d0a9b9..c72d07be6 100644
--- a/examples/albert/utils.py
+++ b/examples/albert/utils.py
@@ -1,6 +1,6 @@
 from typing import Dict, List, Tuple
 
-from pydantic import BaseModel, StrictFloat, confloat, conint
+from pydantic.v1 import BaseModel, StrictFloat, confloat, conint
 
 from hivemind.dht.crypto import RSASignatureValidator
 from hivemind.dht.schema import BytesWithPublicKey, SchemaValidator
diff --git a/hivemind/dht/schema.py b/hivemind/dht/schema.py
index 587afd1fb..de946721f 100644
--- a/hivemind/dht/schema.py
+++ b/hivemind/dht/schema.py
@@ -1,7 +1,7 @@
 import re
 from typing import Any, Dict, Optional, Type
 
-import pydantic
+import pydantic.v1 as pydantic
 
 from hivemind.dht.crypto import RSASignatureValidator
 from hivemind.dht.protocol import DHTProtocol
diff --git a/hivemind/optim/progress_tracker.py b/hivemind/optim/progress_tracker.py
index 9a6ff66e7..6b3f2a709 100644
--- a/hivemind/optim/progress_tracker.py
+++ b/hivemind/optim/progress_tracker.py
@@ -6,7 +6,7 @@
 from typing import Dict, Optional
 
 import numpy as np
-from pydantic import BaseModel, StrictBool, StrictFloat, confloat, conint
+from pydantic.v1 import BaseModel, StrictBool, StrictFloat, confloat, conint
 
 from hivemind.dht import DHT
 from hivemind.dht.schema import BytesWithPublicKey, RSASignatureValidator, SchemaValidator
diff --git a/requirements.txt b/requirements.txt
index df60317d8..5a39ffbcd 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -12,5 +12,5 @@ configargparse>=1.2.3
 py-multihash>=0.2.3
 multiaddr @ git+https://github.com/multiformats/py-multiaddr.git@e01dbd38f2c0464c0f78b556691d655265018cce
 cryptography>=3.4.6
-pydantic>=1.8.1,<2.0
+pydantic>=2.0.0
 packaging>=20.9


Test patch:
diff --git a/tests/test_dht_schema.py b/tests/test_dht_schema.py
index 8c9fd4aeb..120bd361e 100644
--- a/tests/test_dht_schema.py
+++ b/tests/test_dht_schema.py
@@ -2,7 +2,7 @@
 from typing import Dict
 
 import pytest
-from pydantic import BaseModel, StrictInt, conint
+from pydantic.v1 import BaseModel, StrictInt, conint
 
 import hivemind
 from hivemind.dht.node import DHTNode
diff --git a/tests/test_dht_validation.py b/tests/test_dht_validation.py
index 56420d3d7..7ac97dbf3 100644
--- a/tests/test_dht_validation.py
+++ b/tests/test_dht_validation.py
@@ -2,7 +2,7 @@
 from typing import Dict
 
 import pytest
-from pydantic import BaseModel, StrictInt
+from pydantic.v1 import BaseModel, StrictInt
 
 import hivemind
 from hivemind.dht.crypto import RSASignatureValidator