From d1786c80b785054de3b4890333acdeb1e13b37c6 Mon Sep 17 00:00:00 2001 From: Hung Le Date: Fri, 23 Feb 2024 01:30:24 +0700 Subject: [PATCH] fix naming convention --- {prompting => einstein}/__init__.py | 0 {prompting => einstein}/agent.py | 8 +- {prompting => einstein}/base/__init__.py | 0 {prompting => einstein}/base/miner.py | 4 +- {prompting => einstein}/base/neuron.py | 8 +- {prompting => einstein}/base/validator.py | 6 +- {prompting => einstein}/cleaners/__init__.py | 0 .../cleaners/all_cleaners.py | 0 {prompting => einstein}/cleaners/cleaner.py | 2 +- {prompting => einstein}/conversation.py | 4 +- {prompting => einstein}/dendrite.py | 0 {prompting => einstein}/forward.py | 22 +++--- {prompting => einstein}/llm.py | 4 +- {prompting => einstein}/mock.py | 0 {prompting => einstein}/persona.py | 0 {prompting => einstein}/protocol.py | 52 ++++++------- {prompting => einstein}/rewards/__init__.py | 0 .../rewards/advanced_math.py | 2 +- {prompting => einstein}/rewards/float_diff.py | 2 +- {prompting => einstein}/rewards/pipeline.py | 8 +- {prompting => einstein}/rewards/reward.py | 0 {prompting => einstein}/rewards/wolfram.py | 0 {prompting => einstein}/tasks/__init__.py | 0 {prompting => einstein}/tasks/math.py | 2 +- {prompting => einstein}/tasks/task.py | 4 +- {prompting => einstein}/tools/__init__.py | 0 {prompting => einstein}/tools/dataset.py | 0 {prompting => einstein}/utils/__init__.py | 0 {prompting => einstein}/utils/config.py | 0 {prompting => einstein}/utils/logging.py | 6 +- {prompting => einstein}/utils/misc.py | 0 {prompting => einstein}/utils/uids.py | 0 neurons/miner.py | 75 +++++++++++-------- neurons/miners/openai/miner.py | 67 ++++++++--------- neurons/miners/test/echo.py | 10 +-- neurons/miners/test/mock.py | 10 +-- neurons/miners/test/phrase.py | 10 +-- neurons/validator.py | 8 +- setup.py | 2 +- tests/fixtures/dataset.py | 2 +- tests/fixtures/llm.py | 2 +- tests/fixtures/task.py | 2 +- tests/test_agent.py | 4 +- tests/test_cleaner_pipeline.py | 2 +- tests/test_dataset_task_integration.py | 2 +- tests/test_persona.py | 2 +- tests/test_tasks.py | 2 +- tests/test_uids.py | 2 +- 48 files changed, 173 insertions(+), 163 deletions(-) rename {prompting => einstein}/__init__.py (100%) rename {prompting => einstein}/agent.py (95%) rename {prompting => einstein}/base/__init__.py (100%) rename {prompting => einstein}/base/miner.py (98%) rename {prompting => einstein}/base/neuron.py (95%) rename {prompting => einstein}/base/validator.py (98%) rename {prompting => einstein}/cleaners/__init__.py (100%) rename {prompting => einstein}/cleaners/all_cleaners.py (100%) rename {prompting => einstein}/cleaners/cleaner.py (95%) rename {prompting => einstein}/conversation.py (88%) rename {prompting => einstein}/dendrite.py (100%) rename {prompting => einstein}/forward.py (87%) rename {prompting => einstein}/llm.py (97%) rename {prompting => einstein}/mock.py (100%) rename {prompting => einstein}/persona.py (100%) rename {prompting => einstein}/protocol.py (80%) rename {prompting => einstein}/rewards/__init__.py (100%) rename {prompting => einstein}/rewards/advanced_math.py (95%) rename {prompting => einstein}/rewards/float_diff.py (96%) rename {prompting => einstein}/rewards/pipeline.py (94%) rename {prompting => einstein}/rewards/reward.py (100%) rename {prompting => einstein}/rewards/wolfram.py (100%) rename {prompting => einstein}/tasks/__init__.py (100%) rename {prompting => einstein}/tasks/math.py (97%) rename {prompting => einstein}/tasks/task.py (97%) rename {prompting => einstein}/tools/__init__.py (100%) rename {prompting => einstein}/tools/dataset.py (100%) rename {prompting => einstein}/utils/__init__.py (100%) rename {prompting => einstein}/utils/config.py (100%) rename {prompting => einstein}/utils/logging.py (97%) rename {prompting => einstein}/utils/misc.py (100%) rename {prompting => einstein}/utils/uids.py (100%) diff --git a/prompting/__init__.py b/einstein/__init__.py similarity index 100% rename from prompting/__init__.py rename to einstein/__init__.py diff --git a/prompting/agent.py b/einstein/agent.py similarity index 95% rename from prompting/agent.py rename to einstein/agent.py index 1877536..4b3aa9f 100644 --- a/prompting/agent.py +++ b/einstein/agent.py @@ -2,10 +2,10 @@ import time import bittensor as bt from dataclasses import asdict -from prompting.tasks import Task -from prompting.llm import HuggingFaceLLM -from prompting.cleaners.cleaner import CleanerPipeline -from prompting.persona import Persona, create_persona +from einstein.tasks import Task +from einstein.llm import HuggingFaceLLM +from einstein.cleaners.cleaner import CleanerPipeline +from einstein.persona import Persona, create_persona from transformers import Pipeline import warnings diff --git a/prompting/base/__init__.py b/einstein/base/__init__.py similarity index 100% rename from prompting/base/__init__.py rename to einstein/base/__init__.py diff --git a/prompting/base/miner.py b/einstein/base/miner.py similarity index 98% rename from prompting/base/miner.py rename to einstein/base/miner.py index 8889286..6721364 100644 --- a/prompting/base/miner.py +++ b/einstein/base/miner.py @@ -4,8 +4,8 @@ import asyncio import threading import bittensor as bt -from prompting.base.neuron import BaseNeuron -from prompting.utils.config import add_miner_args +from einstein.base.neuron import BaseNeuron +from einstein.utils.config import add_miner_args from traceback import print_exception diff --git a/prompting/base/neuron.py b/einstein/base/neuron.py similarity index 95% rename from prompting/base/neuron.py rename to einstein/base/neuron.py index 52827c9..daf5380 100644 --- a/prompting/base/neuron.py +++ b/einstein/base/neuron.py @@ -6,11 +6,11 @@ from abc import ABC, abstractmethod # Sync calls set weights and also resyncs the metagraph. -from prompting.utils.config import check_config, add_args, config -from prompting.utils.misc import ttl_get_block -from prompting import __spec_version__ as spec_version +from einstein.utils.config import check_config, add_args, config +from einstein.utils.misc import ttl_get_block +from einstein import __spec_version__ as spec_version -from prompting.mock import MockSubtensor, MockMetagraph +from einstein.mock import MockSubtensor, MockMetagraph class BaseNeuron(ABC): diff --git a/prompting/base/validator.py b/einstein/base/validator.py similarity index 98% rename from prompting/base/validator.py rename to einstein/base/validator.py index a40d72c..7e9af8e 100644 --- a/prompting/base/validator.py +++ b/einstein/base/validator.py @@ -9,9 +9,9 @@ from typing import List from traceback import print_exception -from prompting.base.neuron import BaseNeuron -from prompting.mock import MockDendrite -from prompting.utils.config import add_validator_args +from einstein.base.neuron import BaseNeuron +from einstein.mock import MockDendrite +from einstein.utils.config import add_validator_args class BaseValidatorNeuron(BaseNeuron): diff --git a/prompting/cleaners/__init__.py b/einstein/cleaners/__init__.py similarity index 100% rename from prompting/cleaners/__init__.py rename to einstein/cleaners/__init__.py diff --git a/prompting/cleaners/all_cleaners.py b/einstein/cleaners/all_cleaners.py similarity index 100% rename from prompting/cleaners/all_cleaners.py rename to einstein/cleaners/all_cleaners.py diff --git a/prompting/cleaners/cleaner.py b/einstein/cleaners/cleaner.py similarity index 95% rename from prompting/cleaners/cleaner.py rename to einstein/cleaners/cleaner.py index bae75a7..ce171fc 100644 --- a/prompting/cleaners/cleaner.py +++ b/einstein/cleaners/cleaner.py @@ -2,7 +2,7 @@ import bittensor as bt -from prompting.cleaners.all_cleaners import RemoveQuotes, RemoveRoles, PruneEnding +from einstein.cleaners.all_cleaners import RemoveQuotes, RemoveRoles, PruneEnding SUPPORTED_CLEANERS = { "remove_quotes": RemoveQuotes, diff --git a/prompting/conversation.py b/einstein/conversation.py similarity index 88% rename from prompting/conversation.py rename to einstein/conversation.py index 6c7bbd8..5614881 100644 --- a/prompting/conversation.py +++ b/einstein/conversation.py @@ -1,8 +1,8 @@ -from prompting.tasks import ( +from einstein.tasks import ( Task, MathTask, ) -from prompting.tools import ( +from einstein.tools import ( MathDataset, ) diff --git a/prompting/dendrite.py b/einstein/dendrite.py similarity index 100% rename from prompting/dendrite.py rename to einstein/dendrite.py diff --git a/prompting/forward.py b/einstein/forward.py similarity index 87% rename from prompting/forward.py rename to einstein/forward.py index adbd3be..f70552c 100644 --- a/prompting/forward.py +++ b/einstein/forward.py @@ -4,13 +4,13 @@ import bittensor as bt from typing import List -from prompting.agent import HumanAgent -from prompting.dendrite import DendriteResponseEvent -from prompting.conversation import create_task -from prompting.protocol import PromptingSynapse -from prompting.rewards import RewardResult -from prompting.utils.uids import get_random_uids -from prompting.utils.logging import log_event +from einstein.agent import HumanAgent +from einstein.dendrite import DendriteResponseEvent +from einstein.conversation import create_task +from einstein.protocol import CoreSynapse +from einstein.rewards import RewardResult +from einstein.utils.uids import get_random_uids +from einstein.utils.logging import log_event async def run_step( @@ -39,9 +39,9 @@ async def run_step( axons = [self.metagraph.axons[uid] for uid in uids] # Make calls to the network with the prompt. - responses: List[PromptingSynapse] = await self.dendrite( + responses: List[CoreSynapse] = await self.dendrite( axons=axons, - synapse=PromptingSynapse(roles=["user"], messages=[agent.challenge]), + synapse=CoreSynapse(roles=["user"], messages=[agent.challenge]), timeout=timeout, ) @@ -88,7 +88,9 @@ async def forward(self): bt.logging.info( f"📋 Selecting task... from {self.config.neuron.tasks} with distribution {self.config.neuron.task_p}" ) - bt.logging.info(f"Tasks: {self.config.neuron.tasks}, Probabilities: {self.config.neuron.task_p}") + bt.logging.info( + f"Tasks: {self.config.neuron.tasks}, Probabilities: {self.config.neuron.task_p}" + ) # Create a specific task # task_name = np.random.choice( diff --git a/prompting/llm.py b/einstein/llm.py similarity index 97% rename from prompting/llm.py rename to einstein/llm.py index 20867b3..6171179 100644 --- a/prompting/llm.py +++ b/einstein/llm.py @@ -4,9 +4,9 @@ import bittensor as bt from transformers import Pipeline, pipeline -from prompting.mock import MockPipeline +from einstein.mock import MockPipeline -from prompting.cleaners.cleaner import CleanerPipeline +from einstein.cleaners.cleaner import CleanerPipeline def load_pipeline( diff --git a/prompting/mock.py b/einstein/mock.py similarity index 100% rename from prompting/mock.py rename to einstein/mock.py diff --git a/prompting/persona.py b/einstein/persona.py similarity index 100% rename from prompting/persona.py rename to einstein/persona.py diff --git a/prompting/protocol.py b/einstein/protocol.py similarity index 80% rename from prompting/protocol.py rename to einstein/protocol.py index c3f7f95..291f7d1 100644 --- a/prompting/protocol.py +++ b/einstein/protocol.py @@ -5,11 +5,11 @@ from starlette.responses import StreamingResponse -class PromptingSynapse(bt.Synapse): +class CoreSynapse(bt.Synapse): """ - The PromptingSynapse subclass of the Synapse class encapsulates the functionalities related to prompting scenarios. + The CoreSynapse subclass of the Synapse class encapsulates the functionalities related to prompting scenarios. - It specifies three fields - `roles`, `messages` and `completion` - that define the state of the PromptingSynapse object. + It specifies three fields - `roles`, `messages` and `completion` - that define the state of the CoreSynapse object. The `roles` and `messages` are read-only fields defined during object initialization, and `completion` is a mutable field that can be updated as the prompting scenario progresses. @@ -23,18 +23,18 @@ class PromptingSynapse(bt.Synapse): required_hash_fields List[str]: A list of fields that are required for the hash. Methods: - deserialize() -> "PromptingSynapse": Returns the instance of the current object. + deserialize() -> "CoreSynapse": Returns the instance of the current object. - The `PromptingSynapse` class also overrides the `deserialize` method, returning the + The `CoreSynapse` class also overrides the `deserialize` method, returning the instance itself when this method is invoked. Additionally, it provides a `Config` inner class that enforces the validation of assignments (`validate_assignment = True`). - Here is an example of how the `PromptingSynapse` class can be used: + Here is an example of how the `CoreSynapse` class can be used: ```python - # Create a PromptingSynapse instance - prompt = PromptingSynapse(roles=["system", "user"], messages=["Hello", "Hi"]) + # Create a CoreSynapse instance + prompt = CoreSynapse(roles=["system", "user"], messages=["Hello", "Hi"]) # Print the roles and messages print("Roles:", prompt.roles) @@ -56,49 +56,49 @@ class PromptingSynapse(bt.Synapse): Completion: "The meaning of life is 42. Deal with it, human." ``` - This example demonstrates how to create an instance of the `PromptingSynapse` class, access the + This example demonstrates how to create an instance of the `CoreSynapse` class, access the `roles` and `messages` fields, and update the `completion` field. """ class Config: """ - Pydantic model configuration class for PromptingSynapse. This class sets validation of attribute assignment as True. + Pydantic model configuration class for CoreSynapse. This class sets validation of attribute assignment as True. validate_assignment set to True means the pydantic model will validate attribute assignments on the class. """ validate_assignment = True - def deserialize(self) -> "PromptingSynapse": + def deserialize(self) -> "CoreSynapse": """ - Returns the instance of the current PromptingSynapse object. + Returns the instance of the current CoreSynapse object. This method is intended to be potentially overridden by subclasses for custom deserialization logic. - In the context of the PromptingSynapse class, it simply returns the instance itself. However, for subclasses + In the context of the CoreSynapse class, it simply returns the instance itself. However, for subclasses inheriting from this class, it might give a custom implementation for deserialization if need be. Returns: - PromptingSynapse: The current instance of the PromptingSynapse class. + CoreSynapse: The current instance of the CoreSynapse class. """ return self roles: List[str] = pydantic.Field( ..., title="Roles", - description="A list of roles in the PromptingSynapse scenario. Immuatable.", + description="A list of roles in the CoreSynapse scenario. Immuatable.", allow_mutation=False, ) messages: List[str] = pydantic.Field( ..., title="Messages", - description="A list of messages in the PromptingSynapse scenario. Immutable.", + description="A list of messages in the CoreSynapse scenario. Immutable.", allow_mutation=False, ) completion: str = pydantic.Field( "", title="Completion", - description="Completion status of the current PromptingSynapse object. This attribute is mutable and can be updated.", + description="Completion status of the current CoreSynapse object. This attribute is mutable and can be updated.", ) required_hash_fields: List[str] = pydantic.Field( @@ -109,13 +109,13 @@ def deserialize(self) -> "PromptingSynapse": ) -class StreamPromptingSynapse(bt.StreamingSynapse): +class StreamCoreSynapse(bt.StreamingSynapse): """ - StreamPromptingSynapse is a specialized implementation of the `StreamingSynapse` tailored for prompting functionalities within + StreamCoreSynapse is a specialized implementation of the `StreamingSynapse` tailored for prompting functionalities within the Bittensor network. This class is intended to interact with a streaming response that contains a sequence of tokens, which represent prompts or messages in a certain scenario. - As a developer, when using or extending the `StreamPromptingSynapse` class, you should be primarily focused on the structure + As a developer, when using or extending the `StreamCoreSynapse` class, you should be primarily focused on the structure and behavior of the prompts you are working with. The class has been designed to seamlessly handle the streaming, decoding, and accumulation of tokens that represent these prompts. @@ -141,21 +141,21 @@ class StreamPromptingSynapse(bt.StreamingSynapse): - `extract_response_json`: Extracts relevant JSON data from the response, useful for gaining insights on the response's metadata or for debugging purposes. - Note: While you can directly use the `StreamPromptingSynapse` class, it's designed to be extensible. Thus, you can create + Note: While you can directly use the `StreamCoreSynapse` class, it's designed to be extensible. Thus, you can create subclasses to further customize behavior for specific prompting scenarios or requirements. """ roles: List[str] = pydantic.Field( ..., title="Roles", - description="A list of roles in the PromptingSynapse scenario. Immuatable.", + description="A list of roles in the CoreSynapse scenario. Immuatable.", allow_mutation=False, ) messages: List[str] = pydantic.Field( ..., title="Messages", - description="A list of messages in the PromptingSynapse scenario. Immutable.", + description="A list of messages in the CoreSynapse scenario. Immutable.", allow_mutation=False, ) @@ -169,13 +169,13 @@ class StreamPromptingSynapse(bt.StreamingSynapse): completion: str = pydantic.Field( "", title="Completion", - description="Completion status of the current PromptingSynapse object. This attribute is mutable and can be updated.", + description="Completion status of the current CoreSynapse object. This attribute is mutable and can be updated.", ) async def process_streaming_response(self, response: StreamingResponse): """ `process_streaming_response` is an asynchronous method designed to process the incoming streaming response from the - Bittensor network. It's the heart of the StreamPromptingSynapse class, ensuring that streaming tokens, which represent + Bittensor network. It's the heart of the StreamCoreSynapse class, ensuring that streaming tokens, which represent prompts or messages, are decoded and appropriately managed. As the streaming response is consumed, the tokens are decoded from their 'utf-8' encoded format, split based on @@ -223,7 +223,7 @@ def extract_response_json(self, response: StreamingResponse) -> dict: dict: A structured dictionary containing: - Basic response metadata such as name, timeout, total_size, and header_size. - Dendrite and Axon related information extracted from headers. - - Roles and Messages pertaining to the current StreamPromptingSynapse instance. + - Roles and Messages pertaining to the current StreamCoreSynapse instance. - The accumulated completion. """ headers = { diff --git a/prompting/rewards/__init__.py b/einstein/rewards/__init__.py similarity index 100% rename from prompting/rewards/__init__.py rename to einstein/rewards/__init__.py diff --git a/prompting/rewards/advanced_math.py b/einstein/rewards/advanced_math.py similarity index 95% rename from prompting/rewards/advanced_math.py rename to einstein/rewards/advanced_math.py index caa148a..85a0016 100644 --- a/prompting/rewards/advanced_math.py +++ b/einstein/rewards/advanced_math.py @@ -2,7 +2,7 @@ import torch from typing import List from sympy import simplify, symbols, parse_expr -from prompting.rewards import BaseRewardModel, BatchRewardOutput +from einstein.rewards import BaseRewardModel, BatchRewardOutput class AdvancedMathModel(BaseRewardModel): @property diff --git a/prompting/rewards/float_diff.py b/einstein/rewards/float_diff.py similarity index 96% rename from prompting/rewards/float_diff.py rename to einstein/rewards/float_diff.py index a57d076..dbc9037 100644 --- a/prompting/rewards/float_diff.py +++ b/einstein/rewards/float_diff.py @@ -2,7 +2,7 @@ import torch from typing import List from sympy.parsing.sympy_parser import parse_expr -from prompting.rewards import BaseRewardModel, BatchRewardOutput, RewardModelTypeEnum +from einstein.rewards import BaseRewardModel, BatchRewardOutput, RewardModelTypeEnum class FloatDiffModel(BaseRewardModel): diff --git a/prompting/rewards/pipeline.py b/einstein/rewards/pipeline.py similarity index 94% rename from prompting/rewards/pipeline.py rename to einstein/rewards/pipeline.py index b773567..2b10b8c 100644 --- a/prompting/rewards/pipeline.py +++ b/einstein/rewards/pipeline.py @@ -1,9 +1,9 @@ from typing import List -from prompting.tasks import MathTask -from prompting.rewards import BaseRewardModel -from prompting.rewards.float_diff import FloatDiffModel -from prompting.rewards.advanced_math import AdvancedMathModel +from einstein.tasks import MathTask +from einstein.rewards import BaseRewardModel +from einstein.rewards.float_diff import FloatDiffModel +from einstein.rewards.advanced_math import AdvancedMathModel SUPPORTED_TASKS = { "math": MathTask diff --git a/prompting/rewards/reward.py b/einstein/rewards/reward.py similarity index 100% rename from prompting/rewards/reward.py rename to einstein/rewards/reward.py diff --git a/prompting/rewards/wolfram.py b/einstein/rewards/wolfram.py similarity index 100% rename from prompting/rewards/wolfram.py rename to einstein/rewards/wolfram.py diff --git a/prompting/tasks/__init__.py b/einstein/tasks/__init__.py similarity index 100% rename from prompting/tasks/__init__.py rename to einstein/tasks/__init__.py diff --git a/prompting/tasks/math.py b/einstein/tasks/math.py similarity index 97% rename from prompting/tasks/math.py rename to einstein/tasks/math.py index 76bd719..8d81965 100644 --- a/prompting/tasks/math.py +++ b/einstein/tasks/math.py @@ -1,7 +1,7 @@ import sys import bittensor as bt from dataclasses import dataclass -from prompting.tasks import Task +from einstein.tasks import Task @dataclass diff --git a/prompting/tasks/task.py b/einstein/tasks/task.py similarity index 97% rename from prompting/tasks/task.py rename to einstein/tasks/task.py index 263e63e..b6a4414 100644 --- a/prompting/tasks/task.py +++ b/einstein/tasks/task.py @@ -4,9 +4,9 @@ from dataclasses import dataclass from enum import Enum from typing import List, Union, Dict -from prompting.llm import HuggingFaceLLM +from einstein.llm import HuggingFaceLLM from transformers import Pipeline -from prompting.cleaners.cleaner import CleanerPipeline +from einstein.cleaners.cleaner import CleanerPipeline class TaskEvaluationType(Enum): diff --git a/prompting/tools/__init__.py b/einstein/tools/__init__.py similarity index 100% rename from prompting/tools/__init__.py rename to einstein/tools/__init__.py diff --git a/prompting/tools/dataset.py b/einstein/tools/dataset.py similarity index 100% rename from prompting/tools/dataset.py rename to einstein/tools/dataset.py diff --git a/prompting/utils/__init__.py b/einstein/utils/__init__.py similarity index 100% rename from prompting/utils/__init__.py rename to einstein/utils/__init__.py diff --git a/prompting/utils/config.py b/einstein/utils/config.py similarity index 100% rename from prompting/utils/config.py rename to einstein/utils/config.py diff --git a/prompting/utils/logging.py b/einstein/utils/logging.py similarity index 97% rename from prompting/utils/logging.py rename to einstein/utils/logging.py index 73df300..4a82ff6 100644 --- a/prompting/utils/logging.py +++ b/einstein/utils/logging.py @@ -7,7 +7,7 @@ from datetime import datetime from typing import List from loguru import logger -import prompting +import einstein @dataclass class Log: @@ -61,8 +61,8 @@ def init_wandb(self, reinit=False): """Starts a new wandb run.""" tags = [ self.wallet.hotkey.ss58_address, - prompting.__version__, - str(prompting.__spec_version__), + einstein.__version__, + str(einstein.__spec_version__), f"netuid_{self.metagraph.netuid}", ] diff --git a/prompting/utils/misc.py b/einstein/utils/misc.py similarity index 100% rename from prompting/utils/misc.py rename to einstein/utils/misc.py diff --git a/prompting/utils/uids.py b/einstein/utils/uids.py similarity index 100% rename from prompting/utils/uids.py rename to einstein/utils/uids.py diff --git a/neurons/miner.py b/neurons/miner.py index afcba5b..f9df5b8 100644 --- a/neurons/miner.py +++ b/neurons/miner.py @@ -2,13 +2,16 @@ import time import typing import bittensor as bt + # Bittensor Miner Template: -import prompting -from prompting.protocol import PromptingSynapse +import einstein +from einstein.protocol import CoreSynapse + # import base miner class which takes care of most of the boilerplate -from prompting.base.miner import BaseMinerNeuron +from einstein.base.miner import BaseMinerNeuron from datetime import datetime + class Miner(BaseMinerNeuron): """ Your miner neuron class. You should use this class to define your miner's behavior. In particular, you should replace the forward function with your own logic. You may also want to override the blacklist and priority functions according to your needs. @@ -19,13 +22,10 @@ class Miner(BaseMinerNeuron): """ def __init__(self, config=None): - super(Miner, self).__init__(config=config) + super(Miner, self).__init__(config=config) self.identity_tags = None - - async def blacklist( - self, synapse: PromptingSynapse - ) -> typing.Tuple[bool, str]: + async def blacklist(self, synapse: CoreSynapse) -> typing.Tuple[bool, str]: """ Determines whether an incoming request should be blacklisted and thus ignored. Your implementation should define the logic for blacklisting requests based on your needs and desired security parameters. @@ -35,7 +35,7 @@ async def blacklist( requests before they are deserialized to avoid wasting resources on requests that will be ignored. Args: - synapse (PromptingSynapse): A synapse object constructed from the headers of the incoming request. + synapse (CoreSynapse): A synapse object constructed from the headers of the incoming request. Returns: Tuple[bool, str]: A tuple containing a boolean indicating whether the synapse's hotkey is blacklisted, @@ -67,7 +67,7 @@ async def blacklist( ) return False, "Hotkey recognized!" - async def priority(self, synapse: PromptingSynapse) -> float: + async def priority(self, synapse: CoreSynapse) -> float: """ The priority function determines the order in which requests are handled. More valuable or higher-priority requests are processed before others. You should design your own priority mechanism with care. @@ -75,7 +75,7 @@ async def priority(self, synapse: PromptingSynapse) -> float: This implementation assigns priority to incoming requests based on the calling entity's stake in the metagraph. Args: - synapse (PromptingSynapse): The synapse object that contains metadata about the incoming request. + synapse (CoreSynapse): The synapse object that contains metadata about the incoming request. Returns: float: A priority score derived from the stake of the calling entity. @@ -97,34 +97,38 @@ async def priority(self, synapse: PromptingSynapse) -> float: f"Prioritizing {synapse.dendrite.hotkey} with value: ", prirority ) return prirority - + def init_wandb(self): bt.logging.info("Initializing wandb...") - + uid = f"uid_{self.metagraph.hotkeys.index(self.wallet.hotkey.ss58_address)}" net_uid = f"netuid_{self.config.netuid}" tags = [ - self.wallet.hotkey.ss58_address, - net_uid, + self.wallet.hotkey.ss58_address, + net_uid, f"uid_{uid}", - prompting.__version__, - str(prompting.__spec_version__), + einstein.__version__, + str(einstein.__spec_version__), ] - + run_name = None if self.identity_tags: # Add identity tags to run tags - tags += self.identity_tags + tags += self.identity_tags + + # Create run name from identity tags + run_name_tags = [str(tag) for tag in self.identity_tags] - # Create run name from identity tags - run_name_tags = [str(tag) for tag in self.identity_tags] - # Add uid, netuid and timestamp to run name - run_name_tags += [uid, net_uid, datetime.now().strftime('%Y_%m_%d_%H_%M_%S')] + run_name_tags += [ + uid, + net_uid, + datetime.now().strftime("%Y_%m_%d_%H_%M_%S"), + ] # Compose run name - run_name = '_'.join(run_name_tags) - + run_name = "_".join(run_name_tags) + # inits wandb in case it hasn't been inited yet self.wandb_run = wandb.init( name=run_name, @@ -132,13 +136,20 @@ def init_wandb(self): entity=self.config.wandb.entity, config=self.config, mode="online" if self.config.wandb.on else "offline", - tags=tags, + tags=tags, ) - - def log_event(self, timing: float, prompt: str, completion: str, system_prompt: str, extra_info: dict = {}): + + def log_event( + self, + timing: float, + prompt: str, + completion: str, + system_prompt: str, + extra_info: dict = {}, + ): if not getattr(self, "wandb_run", None): self.init_wandb() - + step_log = { "epoch_time": timing, # "block": self.last_epoch_block, @@ -151,10 +162,10 @@ def log_event(self, timing: float, prompt: str, completion: str, system_prompt: "incentive": self.metagraph.I[self.uid].item(), "consensus": self.metagraph.C[self.uid].item(), "dividends": self.metagraph.D[self.uid].item(), - **extra_info + **extra_info, } - bt.logging.info('Logging event to wandb...', step_log) + bt.logging.info("Logging event to wandb...", step_log) wandb.log(step_log) @@ -167,4 +178,4 @@ def log_event(self, timing: float, prompt: str, completion: str, system_prompt: if miner.should_exit: bt.logging.warning("Ending miner...") - break \ No newline at end of file + break diff --git a/neurons/miners/openai/miner.py b/neurons/miners/openai/miner.py index 1e43a7a..d12aa64 100644 --- a/neurons/miners/openai/miner.py +++ b/neurons/miners/openai/miner.py @@ -2,9 +2,11 @@ import time import bittensor as bt import argparse + # Bittensor Miner Template: -import prompting -from prompting.protocol import PromptingSynapse +import einstein +from einstein.protocol import CoreSynapse + # import base miner class which takes care of most of the boilerplate from neurons.miner import Miner @@ -15,8 +17,8 @@ from langchain.callbacks import get_openai_callback import warnings -warnings.filterwarnings("ignore") +warnings.filterwarnings("ignore") class OpenAIMiner(Miner): @@ -24,6 +26,7 @@ class OpenAIMiner(Miner): You should also install the dependencies for this miner, which can be found in the requirements.txt file in this directory. """ + @classmethod def add_args(cls, parser: argparse.ArgumentParser): """ @@ -31,24 +34,23 @@ def add_args(cls, parser: argparse.ArgumentParser): """ super().add_args(parser) - def __init__(self, config=None): super().__init__(config=config) bt.logging.info(f"Initializing with model {self.config.neuron.model_id}...") if self.config.wandb.on: - self.identity_tags = ("openai_miner", ) + (self.config.neuron.model_id, ) - - _ = load_dotenv(find_dotenv()) - api_key = os.environ.get("OPENAI_API_KEY") + self.identity_tags = ("openai_miner",) + (self.config.neuron.model_id,) + + _ = load_dotenv(find_dotenv()) + api_key = os.environ.get("OPENAI_API_KEY") # Set openai key and other args self.model = ChatOpenAI( api_key=api_key, model_name=self.config.neuron.model_id, - max_tokens = self.config.neuron.max_tokens, - temperature = self.config.neuron.temperature, + max_tokens=self.config.neuron.max_tokens, + temperature=self.config.neuron.temperature, ) self.system_prompt = "You are an AI that excels in solving mathematical problems. Always provide responds concisely and helpfully explanations and step-by-step solutions. You are honest about things you don't know." @@ -68,29 +70,27 @@ def get_cost_logging(self, cb): self.accumulated_completion_tokens += cb.completion_tokens self.accumulated_total_cost += cb.total_cost - return { - 'total_tokens': cb.total_tokens, - 'prompt_tokens': cb.prompt_tokens, - 'completion_tokens': cb.completion_tokens, - 'total_cost': cb.total_cost, - 'accumulated_total_tokens': self.accumulated_total_tokens, - 'accumulated_prompt_tokens': self.accumulated_prompt_tokens, - 'accumulated_completion_tokens': self.accumulated_completion_tokens, - 'accumulated_total_cost': self.accumulated_total_cost, + return { + "total_tokens": cb.total_tokens, + "prompt_tokens": cb.prompt_tokens, + "completion_tokens": cb.completion_tokens, + "total_cost": cb.total_cost, + "accumulated_total_tokens": self.accumulated_total_tokens, + "accumulated_prompt_tokens": self.accumulated_prompt_tokens, + "accumulated_completion_tokens": self.accumulated_completion_tokens, + "accumulated_total_cost": self.accumulated_total_cost, } - async def forward( - self, synapse: PromptingSynapse - ) -> PromptingSynapse: + async def forward(self, synapse: CoreSynapse) -> CoreSynapse: """ Processes the incoming synapse by performing a predefined operation on the input data. This method should be replaced with actual logic relevant to the miner's purpose. Args: - synapse (PromptingSynapse): The synapse object containing the 'dummy_input' data. + synapse (CoreSynapse): The synapse object containing the 'dummy_input' data. Returns: - PromptingSynapse: The synapse object with the 'dummy_output' field set to twice the 'dummy_input' value. + CoreSynapse: The synapse object with the 'dummy_output' field set to twice the 'dummy_input' value. The 'forward' function is a placeholder and should be overridden with logic that is appropriate for the miner's intended operation. This method demonstrates a basic transformation of input data. @@ -100,30 +100,27 @@ async def forward( t0 = time.time() bt.logging.debug(f"📧 Message received, forwarding synapse: {synapse}") - prompt = ChatPromptTemplate.from_messages([ - ("system", self.system_prompt), - ("user", "{input}") - ]) + prompt = ChatPromptTemplate.from_messages( + [("system", self.system_prompt), ("user", "{input}")] + ) chain = prompt | self.model | StrOutputParser() role = synapse.roles[-1] message = synapse.messages[-1] - + bt.logging.debug(f"💬 Querying openai: {prompt}") - response = chain.invoke( - {"role": role, "input": message} - ) + response = chain.invoke({"role": role, "input": message}) synapse.completion = response synapse_latency = time.time() - t0 if self.config.wandb.on: self.log_event( - timing=synapse_latency, + timing=synapse_latency, prompt=message, completion=response, system_prompt=self.system_prompt, - extra_info=self.get_cost_logging(cb) + extra_info=self.get_cost_logging(cb), ) bt.logging.debug(f"✅ Served Response: {response}") @@ -146,4 +143,4 @@ async def forward( if miner.should_exit: bt.logging.warning("Ending miner...") - break + break diff --git a/neurons/miners/test/echo.py b/neurons/miners/test/echo.py index 742d061..529b325 100644 --- a/neurons/miners/test/echo.py +++ b/neurons/miners/test/echo.py @@ -3,8 +3,8 @@ import bittensor as bt # Bittensor Miner Template: -import prompting -from prompting.protocol import PromptingSynapse +import einstein +from einstein.protocol import CoreSynapse # import base miner class which takes care of most of the boilerplate from neurons.miner import Miner @@ -18,16 +18,16 @@ class EchoMiner(Miner): def __init__(self, config=None): super().__init__(config=config) - async def forward(self, synapse: PromptingSynapse) -> PromptingSynapse: + async def forward(self, synapse: CoreSynapse) -> CoreSynapse: synapse.completion = synapse.messages[-1] return synapse - async def blacklist(self, synapse: PromptingSynapse) -> typing.Tuple[bool, str]: + async def blacklist(self, synapse: CoreSynapse) -> typing.Tuple[bool, str]: return False, "All good here" - async def priority(self, synapse: PromptingSynapse) -> float: + async def priority(self, synapse: CoreSynapse) -> float: return 1e6 diff --git a/neurons/miners/test/mock.py b/neurons/miners/test/mock.py index 918552f..600172b 100644 --- a/neurons/miners/test/mock.py +++ b/neurons/miners/test/mock.py @@ -3,8 +3,8 @@ import bittensor as bt # Bittensor Miner Template: -import prompting -from prompting.protocol import PromptingSynapse +import einstein +from einstein.protocol import CoreSynapse # import base miner class which takes care of most of the boilerplate from neurons.miner import Miner @@ -18,16 +18,16 @@ class MockMiner(Miner): def __init__(self, config=None): super().__init__(config=config) - async def forward(self, synapse: PromptingSynapse) -> PromptingSynapse: + async def forward(self, synapse: CoreSynapse) -> CoreSynapse: synapse.completion = f"Hey you reached mock miner {self.config.wallet.hotkey!r}. Please leave a message after the tone.. Beep!" return synapse - async def blacklist(self, synapse: PromptingSynapse) -> typing.Tuple[bool, str]: + async def blacklist(self, synapse: CoreSynapse) -> typing.Tuple[bool, str]: return False, "All good here" - async def priority(self, synapse: PromptingSynapse) -> float: + async def priority(self, synapse: CoreSynapse) -> float: return 1e6 diff --git a/neurons/miners/test/phrase.py b/neurons/miners/test/phrase.py index 771f843..a1cbfc4 100644 --- a/neurons/miners/test/phrase.py +++ b/neurons/miners/test/phrase.py @@ -4,8 +4,8 @@ import bittensor as bt # Bittensor Miner Template: -import prompting -from prompting.protocol import PromptingSynapse +import einstein +from einstein.protocol import CoreSynapse # import base miner class which takes care of most of the boilerplate from neurons.miner import Miner @@ -31,16 +31,16 @@ def add_args(cls, parser: argparse.ArgumentParser): def __init__(self, config=None): super().__init__(config=config) - async def forward(self, synapse: PromptingSynapse) -> PromptingSynapse: + async def forward(self, synapse: CoreSynapse) -> CoreSynapse: synapse.completion = self.config.neuron.phrase return synapse - async def blacklist(self, synapse: PromptingSynapse) -> typing.Tuple[bool, str]: + async def blacklist(self, synapse: CoreSynapse) -> typing.Tuple[bool, str]: return False, "All good here" - async def priority(self, synapse: PromptingSynapse) -> float: + async def priority(self, synapse: CoreSynapse) -> float: return 1e6 diff --git a/neurons/validator.py b/neurons/validator.py index 6fdb32e..8d12d9d 100644 --- a/neurons/validator.py +++ b/neurons/validator.py @@ -2,10 +2,10 @@ import torch import bittensor as bt -from prompting.forward import forward -from prompting.llm import load_pipeline -from prompting.base.validator import BaseValidatorNeuron -from prompting.rewards import RewardPipeline +from einstein.forward import forward +from einstein.llm import load_pipeline +from einstein.base.validator import BaseValidatorNeuron +from einstein.rewards import RewardPipeline class Validator(BaseValidatorNeuron): diff --git a/setup.py b/setup.py index 96a5e45..3f6ad09 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ def read_requirements(path): # loading version from setup.py with codecs.open( - os.path.join(here, "prompting/__init__.py"), encoding="utf-8" + os.path.join(here, "einstein/__init__.py"), encoding="utf-8" ) as init_file: version_match = re.search( r"^__version__ = ['\"]([^'\"]*)['\"]", init_file.read(), re.M diff --git a/tests/fixtures/dataset.py b/tests/fixtures/dataset.py index 5da469a..6d45530 100644 --- a/tests/fixtures/dataset.py +++ b/tests/fixtures/dataset.py @@ -1,5 +1,5 @@ -from prompting.tools import MockDataset, MathDataset +from einstein.tools import MockDataset, MathDataset DATASETS = [ # MockDataset, diff --git a/tests/fixtures/llm.py b/tests/fixtures/llm.py index 84186b6..6fd9cca 100644 --- a/tests/fixtures/llm.py +++ b/tests/fixtures/llm.py @@ -1,3 +1,3 @@ -from prompting.mock import MockPipeline +from einstein.mock import MockPipeline LLM_PIPELINE = MockPipeline("This is just another test.") diff --git a/tests/fixtures/task.py b/tests/fixtures/task.py index 37978c7..92b7d20 100644 --- a/tests/fixtures/task.py +++ b/tests/fixtures/task.py @@ -1,4 +1,4 @@ -from prompting.tasks import Task, MathTask +from einstein.tasks import Task, MathTask from .dataset import MATH_CONTEXT TASKS = [ diff --git a/tests/test_agent.py b/tests/test_agent.py index 30acaaa..8d01e21 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -1,6 +1,6 @@ import pytest -from prompting.tasks import Task -from prompting.agent import HumanAgent, create_persona +from einstein.tasks import Task +from einstein.agent import HumanAgent, create_persona from .fixtures.llm import LLM_PIPELINE from .fixtures.task import CONTEXTS, TASKS diff --git a/tests/test_cleaner_pipeline.py b/tests/test_cleaner_pipeline.py index 54c3702..7bbd018 100644 --- a/tests/test_cleaner_pipeline.py +++ b/tests/test_cleaner_pipeline.py @@ -1,4 +1,4 @@ -from prompting.cleaners.cleaner import CleanerPipeline +from einstein.cleaners.cleaner import CleanerPipeline def test_cleaning_pipeline(): diff --git a/tests/test_dataset_task_integration.py b/tests/test_dataset_task_integration.py index cfd16e1..f12e987 100644 --- a/tests/test_dataset_task_integration.py +++ b/tests/test_dataset_task_integration.py @@ -1,5 +1,5 @@ import pytest -from prompting.tasks import Task +from einstein.tasks import Task from .fixtures.llm import LLM_PIPELINE from .fixtures.task import CONTEXTS, TASKS diff --git a/tests/test_persona.py b/tests/test_persona.py index 2d6a40c..560b618 100644 --- a/tests/test_persona.py +++ b/tests/test_persona.py @@ -1,5 +1,5 @@ import pytest -from prompting.persona import Persona, create_persona +from einstein.persona import Persona, create_persona def test_persona_initialization(): assert type(create_persona()) == Persona diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 6e06320..98dcac1 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -1,6 +1,6 @@ import pytest -from prompting.tasks import Task +from einstein.tasks import Task from .fixtures.task import CONTEXTS, TASKS from .fixtures.llm import LLM_PIPELINE diff --git a/tests/test_uids.py b/tests/test_uids.py index 18bcd22..6367586 100644 --- a/tests/test_uids.py +++ b/tests/test_uids.py @@ -2,7 +2,7 @@ import torch import pytest from types import SimpleNamespace -from prompting.utils.uids import get_random_uids +from einstein.utils.uids import get_random_uids def make_mock_neuron(unique_coldkeys=False, unique_ips=False, vpermit_tao_limit=1000):