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

Staging #29

Merged
merged 35 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4045687
Adds config to select only uids with unique coldkeys/ips to prevent n…
steffencruz Jan 16, 2024
839f5ed
Rename test
steffencruz Jan 16, 2024
356c633
Hey....
p-ferreira Jan 17, 2024
a7fbe99
Merge branch 'main' of https://github.com/opentensor/prompting into main
steffencruz Jan 18, 2024
a8c2c1e
Set relevance to zero when completion is empty, and lower the logging…
steffencruz Jan 18, 2024
878a181
Fix bug where relevance was calculated w.r.t. all completions instead…
steffencruz Jan 18, 2024
6988219
Add prompting/requirements to pip install
bkb2135 Jan 18, 2024
afe4a92
Fix docstrings
bkb2135 Jan 18, 2024
3192dcc
Fix saying only 20 GB VRAM needed
bkb2135 Jan 18, 2024
7da51d3
Remove template test
steffencruz Jan 18, 2024
bb65bea
Merge pull request #26 from opentensor/features/relevance-threshold
steffencruz Jan 18, 2024
8834a0c
Merge pull request #27 from opentensor/fix-docstrings
steffencruz Jan 18, 2024
550d7d2
Merge branch 'main' of github.com:opentensor/prompting into tests/rem…
steffencruz Jan 18, 2024
16a3988
Remove circle CI
steffencruz Jan 18, 2024
5b4f737
Only run tests in tests/ dir and only fail on error and failure
steffencruz Jan 18, 2024
a55b446
Adds task tests
steffencruz Jan 18, 2024
ab222c3
Change pip install flag to -e
steffencruz Jan 19, 2024
225747e
Apply minmax scaling to rewards
steffencruz Jan 19, 2024
04e0a38
Fix logging and add try statement in math reward model
steffencruz Jan 19, 2024
ac2f2ea
Remove comment
steffencruz Jan 19, 2024
5d085eb
Fix indentation error
steffencruz Jan 19, 2024
7524531
Add tests
bkb2135 Jan 19, 2024
d2d93f9
Merge pull request #31 from opentensor/features/normalize-rewards
steffencruz Jan 19, 2024
7086c7b
Package install, run only tests in tests/ and remove circleci
steffencruz Jan 19, 2024
e74dd58
Add custom test conditions
steffencruz Jan 19, 2024
a9c945e
Remove undeployed tasks
bkb2135 Jan 19, 2024
f3d2c84
updates default wandb of validators
p-ferreira Jan 19, 2024
866f8e8
Merge pull request #33 from opentensor/tests/remove-template
p-ferreira Jan 19, 2024
e20e03b
Remove math Task from pytest
bkb2135 Jan 19, 2024
17c5391
Merge branch 'main' into features/query-unique-peers
p-ferreira Jan 19, 2024
e371564
Merge branch 'staging' into features/query-unique-peers
p-ferreira Jan 19, 2024
1f43c67
Merge pull request #14 from opentensor/features/query-unique-peers
p-ferreira Jan 19, 2024
be5885d
Merge pull request #34 from opentensor/features/adjust-default-wandb
steffencruz Jan 19, 2024
cf1a25a
Merge branch 'staging' into tests/remove-unused
steffencruz Jan 19, 2024
f603fc0
Merge pull request #28 from opentensor/tests/remove-unused
steffencruz Jan 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
168 changes: 0 additions & 168 deletions .circleci/config.yml

This file was deleted.

5 changes: 3 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest black
pip install -r requirements.txt
pip install -e .
pip install -r prompting/requirements.txt

- name: Lint with flake8
Expand All @@ -42,4 +42,5 @@ jobs:
black .
- name: Test with pytest
run: |
pytest
# run tests in tests/ dir and only fail if there are failures or errors
pytest tests/ --verbose --failed-first --exitfirst --disable-warnings
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ This repository requires python3.8 or higher. To install, simply clone this repo
```bash
git clone https://github.com/opentensor/prompting.git
cd prompting
python -m pip install -r requirements.txt
python -m pip install -r requirements.txt -r prompting/requirements.txt
python -m pip install -e .
```

Expand All @@ -107,7 +107,7 @@ Prior to running a miner or validator, you must [create a wallet](https://github

The validator and base miner are based on [zephyr](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta), which is a fine-tuned Mistral-7B.

**To run a validator or zephyr miner you will need 40GB VRAM (we're working on bringing this down to 32).**
**To run a validator you will need 24GB of VRAM or 18GB of VRAM for a zephyr miner**
```bash
# To run the validator
python neurons/validator.py
Expand Down
4 changes: 2 additions & 2 deletions neurons/miners/zephyr/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ZephyrMiner(Miner):
"""
Base miner which runs zephyr (https://huggingface.co/HuggingFaceH4/zephyr-7b-beta)

This requires a GPU with at least 40GB of memory.
This requires a GPU with at least 20GB of memory.

To run this miner from the project root directory:

Expand All @@ -45,7 +45,7 @@ class ZephyrMiner(Miner):
@classmethod
def add_args(cls, parser: argparse.ArgumentParser):
"""
Adds OpenAI-specific arguments to the command line parser.
Adds arguments to the command line parser.
"""
super().add_args(parser)
parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions prompting/base/neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ def should_set_weights(self) -> bool:
) > self.config.neuron.epoch_length

def save_state(self):
bt.logging.warning(
bt.logging.debug(
"save_state() not implemented for this neuron. You can implement this function to save model checkpoints or other useful data."
)

def load_state(self):
bt.logging.warning(
bt.logging.debug(
"load_state() not implemented for this neuron. You can implement this function to load model checkpoints or other useful data."
)
2 changes: 0 additions & 2 deletions prompting/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ async def run_step(
**response_event.__state_dict__(),
}

bt.logging.debug(f"Step complete. Event:\n{event}")
# BUG: Make sure everything we log is on CPU not GPU
log_event(self, event)

return event
Expand Down
23 changes: 13 additions & 10 deletions prompting/rewards/float_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ def math_score(reference, completion):
if pred is None:
return 0.0

# Convert reference to float (this is okay because we already checked that the reference is a float)
# TODO: More flexible parsing of the reference (just as with the completion)
ref = float(reference)
if pred == ref:
return 1.0
try:

# Compute the difference
diff = abs(ref - pred)/(ref + 1e-6)
# Make sure the difference is between 0 and 1
diff = min(abs(diff), 1)
# Convert reference to float (this is okay because we already checked that the reference is a float)
# TODO: More flexible parsing of the reference (just as with the completion)
ref = float(reference)
if pred == ref:
return 1.0
# Compute the difference
diff = abs(ref - pred)/(ref + 1e-6)
# Make sure the difference is between 0 and 1
diff = min(abs(diff), 1)

return 1.0 - diff
return 1.0 - diff
except Exception:
return 0.0


def reward(self, reference: str, completions: List[str]) -> BatchRewardOutput:
Expand Down
10 changes: 7 additions & 3 deletions prompting/rewards/relevance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ def reward(
self, reference: str, completions: List[str]
) -> BatchRewardOutput:
reference_embedding = self.model.encode(reference, to_numpy=False)
completions_embeddings = self.model.encode(completions, to_numpy=False)
rewards = []
timings = []

for emb in completions_embeddings:
for comp in completions:
t0 = time.time()
rewards.append(cosine_similarity(reference_embedding.reshape(1, -1), emb.reshape(1, -1)))
score = 0
if comp:
emb = self.model.encode(comp, to_numpy=False)
score = cosine_similarity(reference_embedding.reshape(1, -1), emb.reshape(1, -1))

rewards.append(score)
timings.append(time.time() - t0)

output = BatchRewardOutput(
Expand Down
9 changes: 9 additions & 0 deletions prompting/rewards/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class RewardEvent:
"""Contains rewards for all the responses in a batch"""
model_name: str
rewards: torch.FloatTensor
rewards_normalized: torch.FloatTensor
timings: torch.FloatTensor
model_type: RewardModelTypeEnum
batch_time: float
Expand All @@ -27,6 +28,7 @@ class RewardEvent:
def asdict(self) -> dict:
return {
f"{self.model_name}_raw_rewards": self.rewards.tolist(),
f"{self.model_name}_rewards": self.rewards_normalized.tolist(),
f"{self.model_name}_timings": self.timings.tolist(),
f"{self.model_name}_batch_time": self.batch_time,
f"{self.model_name}_extra_info": self.extra_info,
Expand Down Expand Up @@ -119,6 +121,12 @@ class BatchRewardOutput:
rewards: torch.FloatTensor
timings: torch.FloatTensor
extra_info: dict

def __post_init__(self):
if self.rewards.shape != self.timings.shape:
raise ValueError(f"rewards.shape {self.rewards.shape} != timings.shape {self.timings.shape}")

self.rewards_normalized = (self.rewards-self.rewards.min())/(self.rewards.max()-self.rewards.min())


class BaseRewardModel(ABC):
Expand Down Expand Up @@ -153,6 +161,7 @@ def apply(self, reference: str, response_event) -> RewardEvent:
return RewardEvent(
model_name=self.name,
rewards=batch_rewards_output.rewards,
rewards_normalized=batch_rewards_output.rewards_normalized,
model_type=self.model_type,
batch_time=batch_rewards_time,
extra_info=batch_rewards_output.extra_info,
Expand Down
24 changes: 22 additions & 2 deletions prompting/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def add_args(cls, parser):
help="If set, we dont save events to a log file.",
default=False,
)

parser.add_argument(
"--neuron.log_full",
action="store_true",
Expand Down Expand Up @@ -287,10 +287,30 @@ def add_validator_args(cls, parser):
"--wandb.project_name",
type=str,
help="The name of the project where you are sending the new run.",
default="synapse_agent_experiments",
default="alpha-validators",
)

parser.add_argument(
"--wandb.entity",
type=str,
help="The name of the project where you are sending the new run.",
default="opentensor-dev",
)


parser.add_argument(
"--neuron.query_unique_coldkeys",
action="store_true",
help="Only query a single hotkey per coldkey.",
default=False,
)

parser.add_argument(
"--neuron.query_unique_ips",
action="store_true",
help="Only query a single hotkey per ip.",
default=False,
)

def config(cls):
"""
Expand Down
Loading
Loading