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

Code clean up and optimizations #526

Open
wants to merge 6 commits into
base: staging
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .env.validator.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ SN19_API_URL = "e.g. http://24.199.112.174:4051/"
OPENAI_API_KEY = "your_openai_api_key_here"
HF_TOKEN = "your_huggingface_token_here"

# Scoring API.
# Scoring API (optional).
DEPLOY_SCORING_API = true
SCORING_ADMIN_KEY = "123456"
SCORING_API_PORT = 8094
# Scoring key must match the scoring key in the .env.api.
# SCORING_KEY="..."
4 changes: 2 additions & 2 deletions prompting/llms/model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ class AsyncModelScheduler(AsyncLoopRunner):
interval: int = 14400
scoring_queue: list | None = None

async def start(self, scoring_queue: list):
async def start(self, scoring_queue: list, name: str | None = None):
self.scoring_queue = scoring_queue
return await super().start()
return await super().start(name=name)

async def initialise_loop(self):
model_manager.load_always_active_models()
Expand Down
4 changes: 2 additions & 2 deletions prompting/rewards/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class TaskScorer(AsyncLoopRunner):

model_config = ConfigDict(arbitrary_types_allowed=True)

async def start(self, scoring_queue, reward_events):
async def start(self, scoring_queue, reward_events, name: str | None = None):
self.scoring_queue = scoring_queue
self.reward_events = reward_events
return await super().start()
return await super().start(name=name)

def add_to_queue(
self,
Expand Down
4 changes: 2 additions & 2 deletions prompting/weight_setting/weight_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class WeightSetter(AsyncLoopRunner):
class Config:
arbitrary_types_allowed = True

async def start(self, reward_events):
async def start(self, reward_events, name: str | None = None):
self.reward_events = reward_events
global PAST_WEIGHTS

Expand All @@ -159,7 +159,7 @@ async def start(self, reward_events):
PAST_WEIGHTS = []
except Exception as ex:
logger.error(f"Couldn't load weights from file: {ex}")
return await super().start()
return await super().start(name=name)

async def run_step(self):
await asyncio.sleep(0.01)
Expand Down
5 changes: 3 additions & 2 deletions scripts/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def make_completion(client: openai.AsyncOpenAI, prompt: str, stream: bool
"do_sample": True,
"seed": None,
},
"task": "QuestionAnsweringTask",
"task": "InferenceTask",
"mixture": False,
},
)
Expand All @@ -50,11 +50,12 @@ async def main():
# Example API key, replace with yours:
API_KEY = "0566dbe21ee33bba9419549716cd6f1f"
client = openai.AsyncOpenAI(
base_url=f"http://localhost:{PORT}/v1",
base_url=f"http://0.0.0.0:{PORT}/v1",
max_retries=0,
timeout=Timeout(90, connect=30, read=60),
api_key=API_KEY,
)
client._client.headers["api-key"] = API_KEY
response = await make_completion(client=client, prompt="Say 10 random numbers between 1 and 100", stream=True)
print(response)

Expand Down
4 changes: 2 additions & 2 deletions shared/loop_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ async def run_loop(self):
logger.info("Loop has been cleaned up.")
logger.debug("Exiting run_loop")

async def start(self):
async def start(self, name: str | None = None):
"""Start the loop."""
if self.running:
logger.warning("Loop is already running.")
return
self.running = True
logger.debug(f"{self.name}: Starting loop with {'synchronized' if self.sync else 'non-synchronized'} mode")
self._task = asyncio.create_task(self.run_loop())
self._task = asyncio.create_task(self.run_loop(), name=name)

async def stop(self):
"""Stop the loop."""
Expand Down
22 changes: 14 additions & 8 deletions shared/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
class SharedSettings(BaseSettings):
_instance: Optional["SharedSettings"] = None
_instance_mode: Optional[str] = None
# API
VALIDATOR_API: str = Field("0.0.0.0:8094", env="VALIDATOR_API")
VALIDATOR_SCORING_KEY: str = Field("1234567890", env="VALIDATOR_SCORING_KEY")

mode: Literal["api", "validator", "miner", "mock"] = Field("validator", env="MODE")
MOCK: bool = False
Expand Down Expand Up @@ -87,19 +84,28 @@ class SharedSettings(BaseSettings):
HF_TOKEN: Optional[str] = Field(None, env="HF_TOKEN")
DEPLOY_VALIDATOR: bool = Field(True, env="DEPLOY_VALDITAOR")

# ==== API =====
# API key used to access validator organic scoring mechanism (both .env.validator and .env.api).
SCORING_KEY: str | None = Field(None, env="SCORING_KEY")

# Validator scoring API (.env.validator).
DEPLOY_SCORING_API: bool = Field(False, env="DEPLOY_SCORING_API")
SCORING_API_PORT: int = Field(8094, env="SCORING_API_PORT")
SCORING_ADMIN_KEY: str | None = Field(None, env="SCORING_ADMIN_KEY")
SCORE_ORGANICS: bool = Field(False, env="SCORE_ORGANICS")

# API Management (.env.api).
API_PORT: int = Field(8005, env="API_PORT")
API_HOST: str = Field("0.0.0.0", env="API_HOST")

# API Management.
# Validator scoring API address.
VALIDATOR_API: str = Field("0.0.0.0:8094", env="VALIDATOR_API")
# File with keys used to access API.
API_KEYS_FILE: str = Field("api_keys.json", env="API_KEYS_FILE")
# Admin key used to generate API keys.
ADMIN_KEY: str | None = Field(None, env="ADMIN_KEY")
SCORING_KEY: str | None = Field(None, env="SCORING_KEY")
SCORE_ORGANICS: bool = Field(False, env="SCORE_ORGANICS")
# ==============

# Additional Fields.
# Additional Validator Fields.
NETUID: Optional[int] = Field(61, env="NETUID")
TEST: bool = False
OPENAI_API_KEY: Optional[str] = Field(None, env="OPENAI_API_KEY")
Expand Down
Loading