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

260 require data input #55

Merged
merged 48 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0eadc3b
added upload data to miner hf utils. Add upload data whenever miner r…
peterc-yuma Dec 11, 2024
d1d98ce
update challenge to accept a decrytion key. Data should now be encrypted
peterc-yuma Dec 11, 2024
fe7701a
decrypt data and upload to foundryservices dataset
peterc-yuma Dec 11, 2024
8e6cdcd
update decrypt_data
peterc-yuma Dec 11, 2024
3fcae57
update decryption_key to be bytes
peterc-yuma Dec 11, 2024
06dfca4
fix deserialization of decription key
peterc-yuma Dec 11, 2024
17b7af8
updated path for decryption to be the full path to the miners encrypt…
peterc-yuma Dec 11, 2024
418294d
ensure that decryption works from hf path
peterc-yuma Dec 11, 2024
b1f10fe
add logging
peterc-yuma Dec 11, 2024
246de6e
ensure proper format for repo_id when downloading from huggingface
peterc-yuma Dec 11, 2024
5203abd
Update forward.py to decrypt data properly
peterc-yuma Dec 12, 2024
ac72f53
add logging for key
peterc-yuma Dec 12, 2024
752fdc6
add decryption and upload for 146
peterc-yuma Dec 13, 2024
2f4f488
add decryption and upload for 146
peterc-yuma Dec 13, 2024
c51e0d6
add logging to forward
peterc-yuma Dec 13, 2024
47b920f
more logging
peterc-yuma Dec 13, 2024
f7c07a2
try to get correct path for downloading hf data
peterc-yuma Dec 13, 2024
30e4334
more logging
peterc-yuma Dec 13, 2024
a94910a
hopefully can actually download data from miner repo
peterc-yuma Dec 13, 2024
c720675
update store_data
peterc-yuma Dec 13, 2024
970b25b
update temporary file creation
peterc-yuma Dec 13, 2024
ba197fa
updated dataset manager to use hfapi only
peterc-yuma Dec 13, 2024
24b19d4
add hotkey to dataset file structure
peterc-yuma Dec 13, 2024
ada6812
remove nested folder
peterc-yuma Dec 13, 2024
74bf79d
generalize the data decryption and upload
peterc-yuma Dec 13, 2024
c5f1e5a
add back the model confirmation check for scoring miners
peterc-yuma Dec 16, 2024
ccd90a5
remove unecessary logs
peterc-yuma Dec 16, 2024
0284664
Add better docstrings to miner_hf.py functions
peterc-yuma Dec 16, 2024
fd97de6
update file type to be parquet
peterc-yuma Dec 16, 2024
45a3c24
update file type to be parquet
peterc-yuma Dec 16, 2024
3c6efca
update dataset_manager to properly instantiate hf git repo
peterc-yuma Dec 16, 2024
6e2a23b
update forward to check daily for files to upload after market close
peterc-yuma Dec 16, 2024
74f064a
replace print statemtents with bittensor logging in dataset_manager.py
peterc-yuma Dec 16, 2024
d5af897
add unit test for dataset_manager
peterc-yuma Dec 16, 2024
8505612
ensure that data upload can scale to 200 plus miners
peterc-yuma Dec 17, 2024
7ec96d3
incorporate data decryption into the reward structure
peterc-yuma Dec 17, 2024
17f417d
silly mistake
peterc-yuma Dec 17, 2024
9f43269
improve logging
peterc-yuma Dec 17, 2024
bd3f29a
Update env template
peterc-yuma Dec 18, 2024
4e250b8
merged. needs testing
peterc-yuma Dec 18, 2024
d07beef
fix poetry error
peterc-yuma Dec 18, 2024
a475125
fix isort issue
peterc-yuma Dec 18, 2024
b7c9df2
fix test imports
peterc-yuma Dec 19, 2024
ff0bd02
fix yfinance error
peterc-yuma Dec 19, 2024
0ec8642
update config files to reflect new structure
peterc-yuma Dec 19, 2024
8e93c72
suggested changes
peterc-yuma Dec 19, 2024
349acc2
update reward.py
peterc-yuma Dec 19, 2024
877c34e
ensure correct yfinance version
peterc-yuma Dec 19, 2024
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
10 changes: 8 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Copy the contents on this file to a new file called .env
WANDB_API_KEY='REPLACE_WITH_WANDB_API_KEY'
MINER_HF_ACCESS_TOKEN='REPLACE_WITH_HUGGINGFACE_ACCESS_KEY'
HF_ACCESS_TOKEN='REPLACE_WITH_HUGGINGFACE_ACCESS_KEY'

HF_ACCESS_TOKEN = 'REPLACE_WITH_HUGGINGFACE_ACCESS_KEY'
WANDB_API_KEY = 'REPLACE_WITH_WANDB_API_KEY'
# Git credentials
GIT_TOKEN='REPLACE_WITH_GIT_TOKEN'
GIT_USERNAME='REPLACE_WITH_GIT_USERNAME'
GIT_NAME="REPLACE_WITH_GIT_NAME"
GIT_EMAIL="REPLACE_WITH_GIT_EMAIL"
2 changes: 1 addition & 1 deletion miner.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
{
name: 'miner',
script: 'python3',
args: './neurons/miner.py --netuid 28 --logging.debug --logging.trace --subtensor.network local --wallet.name walletName --wallet.hotkey hotkeyName --axon.port 8091 --hf_repo_id foundryservices/bittensor-sn28-base-lstm --model mining_models/base_lstm_new.h5'
args: './snp_oracle/neurons/miner.py --netuid 28 --logging.debug --logging.trace --subtensor.network local --wallet.name walletName --wallet.hotkey hotkeyName --axon.port 8091 --hf_repo_id foundryservices/bittensor-sn28-base-lstm --model mining_models/base_lstm_new.h5'
},
],
};
58 changes: 56 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tensorflow = "^2.18.0"
yfinance = "^0.2.50"
huggingface-hub = "^0.27.0"
loguru = "^0.7.3"
pyarrow = "^18.1.0"
pandas-market-calendars = "^4.4.2"
python-dotenv = "^1.0.1"
scikit-learn = "^1.6.0"
Expand Down
2 changes: 1 addition & 1 deletion snp_oracle/base_miner/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def prep_data(drop_na: bool = True) -> DataFrame:
"""
# Fetch S&P 500 data - when capturing data any interval, the max we can go back is 60 days
# using Yahoo Finance's Python SDK
data = yf.download("^GSPC", period="60d", interval="5m")
data = yf.download("^GSPC", period="1m", interval="5m")

# Calculate technical indicators - all technical indicators computed here are based on the 5m data
# For example - SMA_50, is not a 50-day moving average, but is instead a 50 5m moving average
Expand Down
25 changes: 25 additions & 0 deletions snp_oracle/neurons/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import typing

import bittensor as bt
from cryptography.fernet import Fernet
peterc-yuma marked this conversation as resolved.
Show resolved Hide resolved

# ML imports
from dotenv import load_dotenv
from huggingface_hub import hf_hub_download
from tensorflow.keras.models import load_model
Expand Down Expand Up @@ -183,6 +186,28 @@ async def forward(self, synapse: predictionnet.protocol.Challenge) -> prediction

model = load_model(model_path)
data = prep_data()

# Generate encryption key for this request
encryption_key = Fernet.generate_key()

# Upload encrypted data to HuggingFace
hf_interface = MinerHfInterface(self.config)
success, metadata = hf_interface.upload_data(
hotkey=self.wallet.hotkey.ss58_address,
data=data,
repo_id=self.config.hf_repo_id,
encryption_key=encryption_key,
)

if success:
bt.logging.success(f"Encrypted data uploaded successfully to {metadata['data_path']}")
synapse.data = metadata["data_path"] # Store the data path in synapse
synapse.decryption_key = encryption_key # Provide key to validator
bt.logging.info(f"synapse.decryption_key: {synapse.decryption_key}")
bt.logging.info(f"synapse.data: {synapse.data}")
else:
bt.logging.error(f"Data upload failed: {metadata['error']}")

scaler, _, _ = scale_data(data)
# mse = create_and_save_base_model_lstm(scaler, X, y)

Expand Down
52 changes: 33 additions & 19 deletions snp_oracle/predictionnet/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

class Challenge(bt.Synapse):
"""
A simple dummy protocol representation which uses bt.Synapse as its base.
This protocol helps in handling dummy request and response communication between
the miner and the validator.
Protocol for handling encrypted prediction challenges between miners and validators.
Includes secure handling of decryption keys and manages model/data references.

Attributes:
- dummy_input: An integer value representing the input request sent by the validator.
- dummy_output: An optional integer value which, when filled, represents the response from the miner.
repo_id: Repository identifier where the model is stored
model: Identifier for the specific model to use
decryption_key: Securely stored key for decrypting data/models
data: Identifier for the data to be used
timestamp: Time at which the validation is taking place
prediction: List of predicted values for next 6 5m candles
"""

repo_id: Optional[str] = pydantic.Field(
Expand All @@ -27,34 +30,45 @@ class Challenge(bt.Synapse):
description="Which model to use",
)

# Required request input, filled by sending dendrite caller.
decryption_key: Optional[bytes] = pydantic.Field(
default=None,
title="Decryption Key",
description="Secure key for decrypting sensitive data/models",
)

data: Optional[str] = pydantic.Field(
default=None,
title="Data ID",
description="Which data to use",
)

timestamp: str = pydantic.Field(
...,
title="Timestamp",
description="The time stamp at which the validation is taking place for",
allow_mutation=False,
)
# Optional request output, filled by recieving axon.

prediction: Optional[List[float]] = pydantic.Field(
default=None,
title="Predictions",
description="Next 6 5m candles' predictions for closing price of S&P 500",
)

def deserialize(self) -> int:
def deserialize(self) -> List[float]:
"""
Deserialize the dummy output. This method retrieves the response from
the miner in the form of dummy_output, deserializes it and returns it
as the output of the dendrite.query() call.
Deserialize the prediction output from the miner.

Returns:
- int: The deserialized response, which in this case is the value of dummy_output.

Example:
Assuming a Dummy instance has a dummy_output value of 5:
>>> dummy_instance = Dummy(dummy_input=4)
>>> dummy_instance.dummy_output = 5
>>> dummy_instance.deserialize()
5
List[float]: The deserialized predictions for the next 6 5m candles.
"""
return self.prediction

def get_decryption_key(self) -> Optional[bytes]:
"""
Safely retrieve the decryption key when needed.

Returns:
Optional[bytes]: The raw Fernet key bytes if set, None otherwise.
"""
return self.decryption_key
7 changes: 7 additions & 0 deletions snp_oracle/predictionnet/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ def add_args(cls, parser):
default=4096,
)

parser.add_argument(
"--neuron.organization",
type=str,
help="HuggingFace organization name for dataset storage",
default="foundryservices",
)

# MINER ONLY CONFIG
else:
bt.logging.debug("Adding miner-specific arguments")
Expand Down
Loading
Loading