Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove neurons #1389

Merged
merged 7 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ def turn_console_off():

from bittensor._proto.bittensor_pb2 import ForwardTextPromptingRequest
from bittensor._proto.bittensor_pb2 import ForwardTextPromptingResponse
from bittensor._proto.bittensor_pb2 import MultiForwardTextPromptingRequest
from bittensor._proto.bittensor_pb2 import MultiForwardTextPromptingResponse
from bittensor._proto.bittensor_pb2 import BackwardTextPromptingRequest
from bittensor._proto.bittensor_pb2 import BackwardTextPromptingResponse

Expand All @@ -204,12 +202,6 @@ def turn_console_off():
from bittensor._dendrite.text_prompting.dendrite import TextPromptingDendrite as text_prompting
from bittensor._dendrite.text_prompting.dendrite_pool import TextPromptingDendritePool as text_prompting_pool

# ---- Base Miners -----
from bittensor._neuron.base_miner_neuron import BaseMinerNeuron
from bittensor._neuron.base_validator import BaseValidator
from bittensor._neuron.base_prompting_miner import BasePromptingMiner
from bittensor._neuron.base_huggingface_miner import HuggingFaceMiner

# ---- Errors and Exceptions -----
from bittensor._keyfile.keyfile_impl import KeyFileError as KeyFileError

Expand Down Expand Up @@ -318,19 +310,11 @@ def forward(
return_all: bool = False,
) -> Union[str, List[str]]:
roles, messages = self.format_content( content )
if not return_all:
return self._dendrite.forward(
roles = roles,
messages = messages,
timeout = timeout
).completion
else:
return self._dendrite.multi_forward(
roles = roles,
messages = messages,
timeout = timeout
).multi_completions

return self._dendrite.forward(
roles = roles,
messages = messages,
timeout = timeout
).completion

async def async_forward(
self,
Expand All @@ -339,18 +323,11 @@ async def async_forward(
return_all: bool = False,
) -> Union[str, List[str]]:
roles, messages = self.format_content( content )
if not return_all:
return await self._dendrite.async_forward(
roles = roles,
messages = messages,
timeout = timeout
).completion
else:
return self._dendrite.async_multi_forward(
return await self._dendrite.async_forward(
roles = roles,
messages = messages,
timeout = timeout
).multi_completions
).completion

class BittensorLLM(LLM):
"""Wrapper around Bittensor Prompting Subnetwork.
Expand Down
78 changes: 1 addition & 77 deletions bittensor/_dendrite/text_prompting/dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import grpc
import json
import torch
import asyncio
import bittensor
from typing import Callable, List, Dict, Union
from typing import Callable, List, Union

class DendriteForwardCall( bittensor.DendriteCall ):

Expand Down Expand Up @@ -77,46 +75,6 @@ async def async_backward( self, reward: float, timeout: float = None ) -> 'Dendr
timeout = self.timeout if timeout is None else bittensor.__blocktime__
)


class MultiDendriteForwardCall( bittensor.DendriteCall ):

name: str = "text_prompting_multi_forward"
is_forward: bool = True
multi_completions: List[str] = [""] # To be filled.

def __init__(
self,
dendrite: 'bittensor.TextPromptingDendrite',
messages: List[str],
roles: List[str],
timeout: float = bittensor.__blocktime__,
):
super().__init__( dendrite = dendrite, timeout = timeout )
self.messages = messages
self.roles = roles
self.packed_messages = [json.dumps({"role": role, "content": message}) for role, message in zip(self.roles, self.messages)]

def __repr__(self) -> str:
return f"MultiDendriteForwardCall( {bittensor.utils.codes.code_to_string(self.return_code)}, to: {self.dest_hotkey[:4]}...{self.dest_hotkey[-4:]}, msg: {self.return_message}, n_completion: {len(self.multi_completions)})"

def __str__(self) -> str: return self.__repr__()

def get_callable( self ) -> Callable:
return bittensor.grpc.TextPromptingStub( self.dendrite.channel ).MultiForward

def get_request_proto( self ) -> bittensor.proto.MultiForwardTextPromptingRequest:
return bittensor.MultiForwardTextPromptingRequest( timeout = self.timeout, messages = self.packed_messages )

def apply_response_proto( self, response_proto: bittensor.MultiForwardTextPromptingResponse ):
self.multi_completions = response_proto.multi_completions

def get_inputs_shape(self) -> torch.Size:
return torch.Size( [len(message) for message in self.packed_messages] )

def get_outputs_shape(self) -> torch.Size:
return torch.Size([ len(self.multi_completions) ] )


class DendriteBackwardCall( bittensor.DendriteCall ):

name: str = "text_prompting_backward"
Expand Down Expand Up @@ -198,40 +156,6 @@ async def async_forward(
if return_call: return forward_call
else: return forward_call.completion

def multi_forward(
self,
roles: List[ str ] ,
messages: List[ str ],
timeout: float = bittensor.__blocktime__,
return_call:bool = True,
) -> Union[ str, DendriteForwardCall ]:
forward_call = MultiDendriteForwardCall(
dendrite = self,
messages = messages,
roles = roles,
timeout = timeout,
)
response_call = self.loop.run_until_complete( self.apply( dendrite_call = forward_call ) )
if return_call: return response_call
else: return response_call.multi_completions

async def async_multi_forward(
self,
roles: List[ str ],
messages: List[ str ],
timeout: float = bittensor.__blocktime__,
return_call: bool = True,
) -> Union[ str, DendriteForwardCall ]:
forward_call = MultiDendriteForwardCall(
dendrite = self,
messages = messages,
roles = roles,
timeout = timeout,
)
forward_call = await self.apply( dendrite_call = forward_call )
if return_call: return forward_call
else: return forward_call.multi_completions

def backward(
self,
roles: List[ str ],
Expand Down
Empty file removed bittensor/_neuron/__init__.py
Empty file.
95 changes: 0 additions & 95 deletions bittensor/_neuron/base_huggingface_miner.py

This file was deleted.

Loading