christopi commited on
Commit ·
54a1c12
1
Parent(s): f4b85cb
feat: define TaskWarrantProtocol
Browse files
vidaio_subnet_core/base/miner.py
CHANGED
|
@@ -4,7 +4,7 @@ import threading
|
|
| 4 |
from loguru import logger
|
| 5 |
import time
|
| 6 |
import traceback
|
| 7 |
-
from vidaio_subnet_core.protocol import VideoUpscalingProtocol, LengthCheckProtocol, VideoCompressionProtocol
|
| 8 |
import argparse
|
| 9 |
from .config import add_common_config
|
| 10 |
import os
|
|
@@ -37,6 +37,10 @@ class BaseMiner(ABC):
|
|
| 37 |
forward_fn=self.forward_compression_requests,
|
| 38 |
blacklist_fn=self.blacklist_compression_requests,
|
| 39 |
priority_fn=self.priority_compression_requests,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
)
|
| 41 |
|
| 42 |
self.check_registered()
|
|
@@ -97,6 +101,15 @@ class BaseMiner(ABC):
|
|
| 97 |
@abstractmethod
|
| 98 |
async def priority_compression_requests(self, synapse: VideoCompressionProtocol) -> float: ...
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
def run(self):
|
| 101 |
"""
|
| 102 |
Initiates and manages the main loop for the miner on the Bittensor network. The main loop handles graceful shutdown on keyboard interrupts and logs unforeseen errors.
|
|
|
|
| 4 |
from loguru import logger
|
| 5 |
import time
|
| 6 |
import traceback
|
| 7 |
+
from vidaio_subnet_core.protocol import VideoUpscalingProtocol, LengthCheckProtocol, VideoCompressionProtocol, TaskWarrantProtocol
|
| 8 |
import argparse
|
| 9 |
from .config import add_common_config
|
| 10 |
import os
|
|
|
|
| 37 |
forward_fn=self.forward_compression_requests,
|
| 38 |
blacklist_fn=self.blacklist_compression_requests,
|
| 39 |
priority_fn=self.priority_compression_requests,
|
| 40 |
+
).attach(
|
| 41 |
+
forward_fn=self.forward_task_warrant_requests,
|
| 42 |
+
blacklist_fn=self.blacklist_task_warrant_requests,
|
| 43 |
+
priority_fn=self.priority_task_warrant_requests,
|
| 44 |
)
|
| 45 |
|
| 46 |
self.check_registered()
|
|
|
|
| 101 |
@abstractmethod
|
| 102 |
async def priority_compression_requests(self, synapse: VideoCompressionProtocol) -> float: ...
|
| 103 |
|
| 104 |
+
@abstractmethod
|
| 105 |
+
async def forward_task_warrant_requests(self, synapse: TaskWarrantProtocol) -> bt.Synapse: ...
|
| 106 |
+
|
| 107 |
+
@abstractmethod
|
| 108 |
+
async def blacklist_task_warrant_requests(self, synapse: TaskWarrantProtocol) -> bool: ...
|
| 109 |
+
|
| 110 |
+
@abstractmethod
|
| 111 |
+
async def priority_task_warrant_requests(self, synapse: TaskWarrantProtocol) -> float: ...
|
| 112 |
+
|
| 113 |
def run(self):
|
| 114 |
"""
|
| 115 |
Initiates and manages the main loop for the miner on the Bittensor network. The main loop handles graceful shutdown on keyboard interrupts and logs unforeseen errors.
|
vidaio_subnet_core/protocol.py
CHANGED
|
@@ -21,6 +21,14 @@ class ContentLength(IntEnum):
|
|
| 21 |
# ONE_SIXTY = 160
|
| 22 |
# THREE_TWENTY = 320
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
class UpscalingMinerPayload(BaseModel):
|
| 25 |
reference_video_url: str = Field(
|
| 26 |
description="The URL of the reference video to be optimized",
|
|
@@ -148,4 +156,25 @@ class LengthCheckProtocol(Synapse):
|
|
| 148 |
max_content_length: ContentLength = Field(
|
| 149 |
description="Maximum content length miner can process (5, 10, or 20)",
|
| 150 |
default=ContentLength.FIVE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
)
|
|
|
|
| 21 |
# ONE_SIXTY = 160
|
| 22 |
# THREE_TWENTY = 320
|
| 23 |
|
| 24 |
+
class TaskType(Enum):
|
| 25 |
+
"""
|
| 26 |
+
Enumeration of allowed task types that miners can handle.
|
| 27 |
+
These represent the types of video processing tasks that miners can warrant.
|
| 28 |
+
"""
|
| 29 |
+
COMPRESSION = "compression"
|
| 30 |
+
UPSCALING = "upscaling"
|
| 31 |
+
|
| 32 |
class UpscalingMinerPayload(BaseModel):
|
| 33 |
reference_video_url: str = Field(
|
| 34 |
description="The URL of the reference video to be optimized",
|
|
|
|
| 156 |
max_content_length: ContentLength = Field(
|
| 157 |
description="Maximum content length miner can process (5, 10, or 20)",
|
| 158 |
default=ContentLength.FIVE
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
class TaskWarrantProtocol(Synapse):
|
| 163 |
+
"""
|
| 164 |
+
Protocol for verifying and warranting task types that miners can handle.
|
| 165 |
+
|
| 166 |
+
This protocol ensures that miners can specify which types of video processing
|
| 167 |
+
tasks they are capable of handling. This helps in task distribution and
|
| 168 |
+
ensures miners only receive tasks they can process.
|
| 169 |
+
|
| 170 |
+
Attributes:
|
| 171 |
+
version (Optional[Version]): The version of the protocol implementation.
|
| 172 |
+
warrant_task (TaskType): The type of task the miner can handle,
|
| 173 |
+
must be one of the predefined values (COMPRESSION or UPSCALING).
|
| 174 |
+
"""
|
| 175 |
+
|
| 176 |
+
version: Optional[Version] = None
|
| 177 |
+
warrant_task: TaskType = Field(
|
| 178 |
+
description="Type of task miner can handle: COMPRESSION or UPSCALING",
|
| 179 |
+
default=TaskType.UPSCALING
|
| 180 |
)
|