Skip to content

Commit

Permalink
Merge pull request #59 from opentensor/staging
Browse files Browse the repository at this point in the history
2.1.0 Release
  • Loading branch information
p-ferreira authored Nov 2, 2023
2 parents 94b19ec + 3be91a8 commit d16ba3f
Show file tree
Hide file tree
Showing 27 changed files with 677 additions and 194 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,7 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

localtesting/
localtesting/

# pm2 config file
app.config.js
2 changes: 1 addition & 1 deletion docs/running_a_validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ btcli wallet faucet --wallet.name validator --subtensor.network test
Register your UID on the test network:

```sh
btcli wallet recycle_register --subtensor.network test
btcli subnets register --subtensor.network test
```

## 5. Start the Process
Expand Down
3 changes: 1 addition & 2 deletions neurons/miners/bittensorLM/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ usage: miner.py [-h] [--axon.port AXON.PORT] [--subtensor.network SUBTENSOR.NETW
[--miner.blacklist.force_validator_permit] [--miner.blacklist.allow_non_registered] [--miner.blacklist.minimum_stake_requirement MINER.BLACKLIST.MINIMUM_STAKE_REQUIREMENT]
[--miner.blacklist.prompt_cache_block_span MINER.BLACKLIST.PROMPT_CACHE_BLOCK_SPAN] [--miner.blacklist.use_prompt_cache] [--miner.blacklist.min_request_period MINER.BLACKLIST.MIN_REQUEST_PERIOD]
[--miner.priority.default MINER.PRIORITY.DEFAULT] [--miner.priority.time_stake_multiplicate MINER.PRIORITY.TIME_STAKE_MULTIPLICATE]
[--miner.priority.len_request_timestamps MINER.PRIORITY.LEN_REQUEST_TIMESTAMPS] [--miner.no_set_weights] [--miner.no_serve] [--miner.no_start_axon] [--miner.no_register] [--miner.mock_subtensor] [--wandb.on]
[--miner.priority.len_request_timestamps MINER.PRIORITY.LEN_REQUEST_TIMESTAMPS] [--miner.no_set_weights] [--miner.no_serve] [--miner.no_start_axon] [--miner.mock_subtensor] [--wandb.on]
[--wandb.project_name WANDB.PROJECT_NAME] [--wandb.entity WANDB.ENTITY] [--logging.debug] [--logging.trace] [--logging.record_log] [--logging.logging_dir LOGGING.LOGGING_DIR] [--wallet.name WALLET.NAME]
[--wallet.hotkey WALLET.HOTKEY] [--wallet.path WALLET.PATH] [--config CONFIG] [--strict] [--no_version_checking] [--no_prompt]
Expand Down Expand Up @@ -60,7 +60,6 @@ options:
--miner.no_serve If True, the miner doesnt serve the axon.
--miner.no_start_axon
If True, the miner doesnt start the axon.
--miner.no_register If True, the miner doesnt register its wallet.
--miner.mock_subtensor
If True, the miner will allow non-registered hotkeys to mine.
--wandb.on Turn on wandb.
Expand Down
3 changes: 1 addition & 2 deletions neurons/miners/openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ usage: miner.py [-h] [--axon.port AXON.PORT] [--subtensor.network SUBTENSOR.NETW
[--miner.blacklist.force_validator_permit] [--miner.blacklist.allow_non_registered] [--miner.blacklist.minimum_stake_requirement MINER.BLACKLIST.MINIMUM_STAKE_REQUIREMENT]
[--miner.blacklist.prompt_cache_block_span MINER.BLACKLIST.PROMPT_CACHE_BLOCK_SPAN] [--miner.blacklist.use_prompt_cache] [--miner.blacklist.min_request_period MINER.BLACKLIST.MIN_REQUEST_PERIOD]
[--miner.priority.default MINER.PRIORITY.DEFAULT] [--miner.priority.time_stake_multiplicate MINER.PRIORITY.TIME_STAKE_MULTIPLICATE]
[--miner.priority.len_request_timestamps MINER.PRIORITY.LEN_REQUEST_TIMESTAMPS] [--miner.no_set_weights] [--miner.no_serve] [--miner.no_start_axon] [--miner.no_register] [--miner.mock_subtensor] [--wandb.on]
[--miner.priority.len_request_timestamps MINER.PRIORITY.LEN_REQUEST_TIMESTAMPS] [--miner.no_set_weights] [--miner.no_serve] [--miner.no_start_axon] [--miner.mock_subtensor] [--wandb.on]
[--wandb.project_name WANDB.PROJECT_NAME] [--wandb.entity WANDB.ENTITY] [--logging.debug] [--logging.trace] [--logging.record_log] [--logging.logging_dir LOGGING.LOGGING_DIR] [--wallet.name WALLET.NAME]
[--wallet.hotkey WALLET.HOTKEY] [--wallet.path WALLET.PATH] [--config CONFIG] [--strict] [--no_version_checking] [--no_prompt]
Expand Down Expand Up @@ -84,7 +84,6 @@ options:
--miner.no_serve If True, the miner doesnt serve the axon.
--miner.no_start_axon
If True, the miner doesnt start the axon.
--miner.no_register If True, the miner doesnt register its wallet.
--miner.mock_subtensor
If True, the miner will allow non-registered hotkeys to mine.
--wandb.on Turn on wandb.
Expand Down
3 changes: 1 addition & 2 deletions neurons/miners/vicuna/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ usage: miner.py [-h] [--axon.port AXON.PORT] [--subtensor.network SUBTENSOR.NETW
[--miner.blacklist.force_validator_permit] [--miner.blacklist.allow_non_registered] [--miner.blacklist.minimum_stake_requirement MINER.BLACKLIST.MINIMUM_STAKE_REQUIREMENT]
[--miner.blacklist.prompt_cache_block_span MINER.BLACKLIST.PROMPT_CACHE_BLOCK_SPAN] [--miner.blacklist.use_prompt_cache] [--miner.blacklist.min_request_period MINER.BLACKLIST.MIN_REQUEST_PERIOD]
[--miner.priority.default MINER.PRIORITY.DEFAULT] [--miner.priority.time_stake_multiplicate MINER.PRIORITY.TIME_STAKE_MULTIPLICATE]
[--miner.priority.len_request_timestamps MINER.PRIORITY.LEN_REQUEST_TIMESTAMPS] [--miner.no_set_weights] [--miner.no_serve] [--miner.no_start_axon] [--miner.no_register] [--miner.mock_subtensor] [--wandb.on]
[--miner.priority.len_request_timestamps MINER.PRIORITY.LEN_REQUEST_TIMESTAMPS] [--miner.no_set_weights] [--miner.no_serve] [--miner.no_start_axon] [--miner.mock_subtensor] [--wandb.on]
[--wandb.project_name WANDB.PROJECT_NAME] [--wandb.entity WANDB.ENTITY] [--logging.debug] [--logging.trace] [--logging.record_log] [--logging.logging_dir LOGGING.LOGGING_DIR] [--wallet.name WALLET.NAME]
[--wallet.hotkey WALLET.HOTKEY] [--wallet.path WALLET.PATH] [--config CONFIG] [--strict] [--no_version_checking] [--no_prompt]
Expand Down Expand Up @@ -115,7 +115,6 @@ options:
--miner.no_serve If True, the miner doesnt serve the axon.
--miner.no_start_axon
If True, the miner doesnt start the axon.
--miner.no_register If True, the miner doesnt register its wallet.
--miner.mock_subtensor
If True, the miner will allow non-registered hotkeys to mine.
--wandb.on Turn on wandb.
Expand Down
28 changes: 19 additions & 9 deletions neurons/validators/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@
# Load gating models
from prompting.validators.reward import (
Blacklist,
TaskValidator,
NSFWRewardModel,
DirectPreferenceRewardModel,
OpenAssistantRewardModel,
ReciprocateRewardModel,
RelevanceRewardModel,
MockRewardModel,
DahoasRewardModel,
DiversityRewardModel,
PromptRewardModel,
RewardModelType,
)

from prompting.validators.penalty import (
TaskValidationPenaltyModel,
KeywordMatchPenaltyModel,
ContentMatchPenaltyModel,
)


class neuron:
@classmethod
Expand Down Expand Up @@ -189,8 +193,12 @@ def __init__(self):
self.blacklist,
MockRewardModel(RewardModelType.nsfw.value),
]
self.penalty_functions = [
TaskValidationPenaltyModel(max_penalty=0.1),
ContentMatchPenaltyModel(max_penalty=0.1),
KeywordMatchPenaltyModel(max_penalty=1),
]
bt.logging.debug(str(self.reward_functions))
self.blacklist = MockRewardModel(RewardModelType.blacklist.value)
else:
self.reward_weights = torch.tensor(
[
Expand Down Expand Up @@ -245,11 +253,6 @@ def __init__(self):
if not self.config.neuron.blacklist_off
else MockRewardModel(RewardModelType.blacklist.value)
)
task_validator = (
TaskValidator()
if not self.config.neuron.task_validator_off
else MockRewardModel(RewardModelType.task_validator.value)
)
relevance_model = (
RelevanceRewardModel(device=self.device)
if not self.config.neuron.relevance_off
Expand All @@ -268,13 +271,20 @@ def __init__(self):

self.masking_functions = [
self.blacklist,
task_validator,
relevance_model,
self.diversity_model,
nsfw_model,
]

self.penalty_functions = [
TaskValidationPenaltyModel(max_penalty=0.1),
ContentMatchPenaltyModel(max_penalty=0.1),
KeywordMatchPenaltyModel(max_penalty=1),
]

bt.logging.debug(str(self.reward_functions))
bt.logging.debug(str(self.masking_functions))
bt.logging.debug(str(self.penalty_functions))

# Init the event loop.
self.loop = asyncio.get_event_loop()
Expand Down
6 changes: 0 additions & 6 deletions prompting/baseminer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,6 @@ def get_config() -> "bt.Config":
help="If True, the miner doesnt start the axon.",
default=False,
)
parser.add_argument(
"--miner.no_register",
action="store_true",
help="If True, the miner doesnt register its wallet.",
default=False,
)

# Mocks.
parser.add_argument(
Expand Down
8 changes: 4 additions & 4 deletions prompting/baseminer/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ def __init__(self, config=None, axon=None, wallet=None, subtensor=None):

# Activating Bittensor's logging with the set configurations.
bt.logging(config=self.config, logging_dir=self.config.full_path)
bt.logging.info(
f"Running miner for subnet: {self.config.netuid} on network: {self.config.subtensor.chain_endpoint} with config:"
)

if not self.config.miner.blacklist.force_validator_permit:
bt.logging.warning(
Expand All @@ -89,7 +86,10 @@ def __init__(self, config=None, axon=None, wallet=None, subtensor=None):

# subtensor manages the blockchain connection, facilitating interaction with the Bittensor blockchain.
self.subtensor = subtensor or bt.subtensor(config=self.config)
bt.logging.info(f"Subtensor: {subtensor}")
bt.logging.info(f"Subtensor: {self.subtensor}")
bt.logging.info(
f"Running miner for subnet: {self.config.netuid} on network: {self.subtensor.chain_endpoint} with config:"
)

# metagraph provides the network's current state, holding state about other participants in a subnet.
self.metagraph = self.subtensor.metagraph(self.config.netuid)
Expand Down
16 changes: 10 additions & 6 deletions prompting/baseminer/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run(self):
Initiates and manages the main loop for the miner on the Bittensor network.
This function performs the following primary tasks:
1. Optionally registers the miner's wallet with the network.
1. Check for registration on the Bittensor network.
2. Attaches the miner's forward, blacklist, and priority functions to its axon.
3. Starts the miner's axon, making it active on the network.
4. Regularly updates the metagraph with the latest network state.
Expand All @@ -48,12 +48,16 @@ def run(self):
KeyboardInterrupt: If the miner is stopped by a manual interruption.
Exception: For unforeseen errors during the miner's operation, which are logged for diagnosis.
"""
# --- Optionally register the wallet.
if not self.config.miner.no_register:
bt.logging.info(
f"Registering wallet: {self.wallet} on netuid {self.config.netuid}"
# --- Check for registration.
if not self.subtensor.is_hotkey_registered(
netuid=self.config.netuid,
hotkey=self.wallet.hotkey.ss58_address,
):
bt.logging.error(
f"Wallet: {self.wallet} is not registered on netuid {self.config.netuid}"
f"Please register the hotkey using `btcli subnets register` before trying again"
)
self.subtensor.register(netuid=self.config.netuid, wallet=self.wallet)
exit()

# Serve passes the axon information to the network + netuid we are hosting on.
# This will auto-update if the axon port of external ip have changed.
Expand Down
37 changes: 1 addition & 36 deletions prompting/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,6 @@ class StreamPrompting(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.
Example usage:
```python
stream_prompter = StreamPrompting(roles=["role1", "role2"], messages=["message1", "message2"])
# Process a streaming response...
stream_prompter.process_streaming_response(response)
# Access the result
result = stream_prompter.deserialize()
# Extract response metadata
json_info = stream_prompter.extract_response_json(response)
```
Note: While you can directly use the `StreamPrompting` class, it's designed to be extensible. Thus, you can create
subclasses to further customize behavior for specific prompting scenarios or requirements.
"""
Expand Down Expand Up @@ -215,18 +204,6 @@ async def process_streaming_response(self, response: StreamingResponse):
Args:
response: The streaming response object containing the content chunks to be processed. Each chunk in this
response is expected to be a set of tokens that can be decoded and split into individual messages or prompts.
Usage:
Generally, this method is called when there's an incoming streaming response to be processed.
```python
stream_prompter = StreamPrompting(roles=["role1", "role2"], messages=["message1", "message2"])
await stream_prompter.process_streaming_response(response)
```
Note:
It's important to remember that this method is asynchronous. Ensure it's called within an appropriate
asynchronous context.
"""
if self.completion is None:
self.completion = ""
Expand All @@ -235,6 +212,7 @@ async def process_streaming_response(self, response: StreamingResponse):
for token in tokens:
if token:
self.completion += token
yield tokens

def deserialize(self) -> str:
"""
Expand Down Expand Up @@ -266,19 +244,6 @@ def extract_response_json(self, response: StreamingResponse) -> dict:
- Dendrite and Axon related information extracted from headers.
- Roles and Messages pertaining to the current StreamPrompting instance.
- The accumulated completion.
Usage:
This method can be used after processing a response to gather detailed metadata:
```python
stream_prompter = StreamPrompting(roles=["role1", "role2"], messages=["message1", "message2"])
# After processing the response...
json_info = stream_prompter.extract_response_json(response)
```
Note:
While the primary output is the structured dictionary, understanding this output can be instrumental in
troubleshooting or in extracting specific insights about the interaction with the Bittensor network.
"""
headers = {
k.decode("utf-8"): v.decode("utf-8")
Expand Down
2 changes: 1 addition & 1 deletion prompting/validators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from . import event
from . import dataset

__version__ = "2.0.2"
__version__ = "2.1.0"
version_split = __version__.split(".")
__spec_version__ = (
(1000 * int(version_split[0]))
Expand Down
2 changes: 1 addition & 1 deletion prompting/validators/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def add_args(cls, parser):
"--neuron.num_followup_steps",
type=int,
help="How many followup steps to take.",
default=4,
default=3,
)

parser.add_argument(
Expand Down
Loading

0 comments on commit d16ba3f

Please sign in to comment.