Skip to content

chore: lint with ruff #106

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

Merged
merged 3 commits into from
Mar 5, 2025
Merged
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: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ jobs:
run: |
source env/bin/activate
ruff format --check
- name: Run Ruff linting
run: |
source env/bin/activate
ruff check
2 changes: 0 additions & 2 deletions TEST_get_emission.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import bittensor as bt
from bittensor_wallet import Wallet
from bittensor import Balance, tao
import time
import random

Expand Down
3 changes: 0 additions & 3 deletions docs/stream_tutorial/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ async def main():
print()
if isinstance(chunk, list):
print(chunk[0], end="", flush=True)
else:
# last object yielded is the synapse itself with completion filled
synapse = chunk
break

# Run the main function with asyncio
Expand Down
10 changes: 4 additions & 6 deletions docs/stream_tutorial/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import bittensor as bt
from transformers import GPT2Tokenizer
from typing import List, Dict, Tuple, Union, Callable, Awaitable
from typing import Dict, Tuple

from protocol import StreamPrompting
from config import get_config, check_config
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(self, config=None, axon=None, wallet=None, subtensor=None):
# The axon handles request processing, allowing validators to send this process requests.
self.axon = axon or bt.axon(wallet=self.wallet, port=self.config.axon.port)
# Attach determiners which functions are called when servicing a request.
bt.logging.info(f"Attaching forward function to axon.")
bt.logging.info("Attaching forward function to axon.")
print(f"Attaching forward function to axon. {self._prompt}")
self.axon.attach(
forward_fn=self._prompt,
Expand Down Expand Up @@ -166,12 +166,10 @@ def run(self):
bt.logging.info(f"Miner starting at block: {self.last_epoch_block}")

# This loop maintains the miner's operations until intentionally stopped.
bt.logging.info(f"Starting main loop")
bt.logging.info("Starting main loop")
step = 0
try:
while not self.should_exit:
start_epoch = time.time()

# --- Wait until next epoch.
current_block = self.subtensor.get_current_block()
while (
Expand Down Expand Up @@ -215,7 +213,7 @@ def run(self):
exit()

# In case of unforeseen errors, the miner will log the error and continue operations.
except Exception as e:
except Exception:
bt.logging.error(traceback.format_exc())

def run_in_background_thread(self):
Expand Down
3 changes: 1 addition & 2 deletions docs/stream_tutorial/protocol.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pydantic
import bittensor as bt

from abc import ABC, abstractmethod
from typing import List, Union, Callable, Awaitable
from typing import List
from starlette.responses import StreamingResponse


Expand Down
3 changes: 0 additions & 3 deletions neurons/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
os.environ["USE_TORCH"] = "1"

import time
import json
import typing
import requests
import asyncio
import bittensor as bt

# Bittensor Miner Template:
Expand Down
14 changes: 7 additions & 7 deletions neurons/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@
MIN_LENGTH_BOOST_TOKEN_COUNT,
MAX_LENGTH_BOOST_TOKEN_COUNT,
STUFFED_DESCRIPTION_PUNISHMENT,
FOCUS_MIN_SCORE,
MIN_AUDIO_LENGTH_SECONDS,
MAX_AUDIO_LENGTH_SECONDS,
MIN_AUDIO_LENGTH_SCORE,
SPEECH_CONTENT_SCALING_FACTOR,
SPEAKER_DOMINANCE_SCALING_FACTOR,
BACKGROUND_NOISE_SCALING_FACTOR,
Expand All @@ -78,7 +76,7 @@
import traceback
import random
import datetime as dt
from typing import List, Tuple, Optional, BinaryIO, Dict
from typing import List, Tuple, Optional, Dict
import asyncio
from aiohttp import ClientSession, BasicAuth
import os
Expand Down Expand Up @@ -918,15 +916,17 @@ async def check_videos_and_calculate_rewards_youtube(
score = max(score, MIN_SCORE)

# Log all our scores
bt.logging.info(f"""
bt.logging.info(
f"""
is_unique: {[not is_sim for is_sim in is_too_similar]},
video cosine sim: {video_description_relevance_scores},
audio cosine sim: {audio_description_relevance_scores},
description relevance scores: {description_relevance_scores},
query relevance scores: {query_relevance_scores},
length scalers: {length_scalers},
total score: {score}
""")
"""
)

# Upload our final results to API endpoint for index and dataset insertion. Include leaderboard statistics
miner_hotkey = videos.axon.hotkey
Expand Down Expand Up @@ -1031,7 +1031,7 @@ async def upload_video_metadata(
json=payload,
) as response:
response.raise_for_status()
result = await response.json()
await response.json()
return True
except Exception as e:
bt.logging.debug(f"Error trying upload_video_metadata_endpoint: {e}")
Expand Down Expand Up @@ -1084,7 +1084,7 @@ async def upload_audio_metadata(
json=payload,
) as response:
response.raise_for_status()
result = await response.json()
await response.json()
return True
except Exception as e:
bt.logging.debug(f"Error trying upload_audio_metadata_endpoint: {e}")
Expand Down
8 changes: 4 additions & 4 deletions omega/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)

# Import all submodules.
from . import protocol
from . import base
from . import validator
from .subnet_links import SUBNET_LINKS
from . import protocol # noqa: E402, F401
from . import base # noqa: E402, F401
from . import validator # noqa: E402, F401
from .subnet_links import SUBNET_LINKS # noqa: E402, F401
2 changes: 0 additions & 2 deletions omega/audio_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
np.NAN = np.nan
from pyannote.audio import Pipeline
import librosa
import os
import dotenv
import pandas as pd
import torch
Expand Down Expand Up @@ -127,7 +126,6 @@ def total_score(self, audio_arr, sr, timestamps_start, timestamps_end, speakers)

if __name__ == "__main__":
from datasets import load_dataset
import huggingface_hub

repo_id = "diarizers-community/voxconverse"

Expand Down
4 changes: 2 additions & 2 deletions omega/base/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, config=None):
self.axon = bt.axon(wallet=self.wallet, config=self.config)

# Attach determiners which functions are called when servicing a request.
bt.logging.info(f"Attaching forward function to miner axon.")
bt.logging.info("Attaching forward function to miner axon.")
self.axon.attach(
forward_fn=self.forward_videos,
blacklist_fn=self.blacklist_videos,
Expand Down Expand Up @@ -137,7 +137,7 @@ def run(self):
exit()

# In case of unforeseen errors, the miner will log the error and continue operations.
except Exception as e:
except Exception:
bt.logging.error(traceback.format_exc())

def run_in_background_thread(self):
Expand Down
1 change: 0 additions & 1 deletion omega/base/neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# DEALINGS IN THE SOFTWARE.

import copy
import typing
import datetime as dt

import bittensor as bt
Expand Down
6 changes: 3 additions & 3 deletions omega/base/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from omega.base.neuron import BaseNeuron
from omega.mock import MockDendrite
from omega.utils.config import add_validator_args
from omega.constants import FOCUS_REWARDS_PERCENT, AUDIO_REWARDS_PERCENT
from omega.constants import AUDIO_REWARDS_PERCENT


class BaseValidatorNeuron(BaseNeuron):
Expand Down Expand Up @@ -191,7 +191,7 @@ def run(self):
break

if self.config.neuron.auto_update and self.should_restart():
bt.logging.info(f"Validator is out of date, quitting to restart.")
bt.logging.info("Validator is out of date, quitting to restart.")
raise KeyboardInterrupt

# Sync metagraph and potentially set weights.
Expand Down Expand Up @@ -320,7 +320,7 @@ def set_weights(self):
# Check if self.scores contains any NaN values and log a warning if it does.
if torch.isnan(self.scores).any():
bt.logging.warning(
f"Scores contain NaN values. This may be due to a lack of responses from miners, or a bug in your reward functions."
"Scores contain NaN values. This may be due to a lack of responses from miners, or a bug in your reward functions."
)

self.scores, self.focus_scores, self.audio_score_arr = self.pad_tensors(
Expand Down
2 changes: 1 addition & 1 deletion omega/diarization_metric.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyannote.core import Segment, Timeline, Annotation
from pyannote.core import Segment, Annotation
from pyannote.metrics.diarization import DiarizationErrorRate
from omega.diarization_pipeline import CustomDiarizationPipeline
import numpy as np
Expand Down
6 changes: 2 additions & 4 deletions omega/imagebind_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from imagebind import data
from imagebind.models import imagebind_model
from imagebind.models.imagebind_model import ModalityType
from imagebind.models.multimodal_preprocessors import SimpleTokenizer, TextPreprocessor
from imagebind.models.multimodal_preprocessors import SimpleTokenizer
from pydantic import BaseModel
import torch

Expand Down Expand Up @@ -135,7 +135,7 @@ def generate_text_embeddings(self, text: str):
def get_inputs(self, video_file: BinaryIO) -> dict:
audio_file = video_utils.copy_audio(video_file.name)
try:
duration = video_utils.get_video_duration(video_file.name)
video_utils.get_video_duration(video_file.name)
video_data = data.load_and_transform_video_data(
[video_file.name],
self.device,
Expand Down Expand Up @@ -180,7 +180,6 @@ def embed(self, descriptions: List[str], video_files: List[BinaryIO]) -> Embeddi
@torch.no_grad()
def embed_only_video(self, video_files: List[BinaryIO]) -> Embeddings:
video_filepaths = [video_file.name for video_file in video_files]
durations = [video_utils.get_video_duration(f.name) for f in video_files]
embeddings = self.imagebind(
{
ModalityType.VISION: [
Expand All @@ -201,7 +200,6 @@ def embed_video_and_text(
self, video_files: List[BinaryIO], descriptions: List[str]
) -> Embeddings:
video_filepaths = [video_file.name for video_file in video_files]
durations = [video_utils.get_video_duration(f.name) for f in video_files]
embeddings = self.imagebind(
{
ModalityType.VISION: [
Expand Down
1 change: 0 additions & 1 deletion omega/miner_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
MAX_VIDEO_LENGTH,
FIVE_MINUTES,
MAX_AUDIO_LENGTH_SECONDS,
MIN_AUDIO_LENGTH_SECONDS,
)
from omega import video_utils
from omega.diarization_pipeline import CustomDiarizationPipeline
Expand Down
1 change: 0 additions & 1 deletion omega/unstuff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import random
import torch.nn.functional as F
from omega.imagebind_wrapper import (
split_text_by_token_limit,
SimpleTokenizer,
BPE_PATH,
split_text_by_token_limit,
Expand Down
6 changes: 3 additions & 3 deletions omega/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import config
from . import misc
from . import uids
from . import config # noqa: F401
from . import misc # noqa: F401
from . import uids # noqa: F401
2 changes: 0 additions & 2 deletions omega/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# DEALINGS IN THE SOFTWARE.

import time
import math
import hashlib as rpccheckhealth
from math import floor
from typing import Callable, Any
from functools import lru_cache, update_wrapper
Expand Down
2 changes: 0 additions & 2 deletions omega/video_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import ffmpeg
from pydantic import BaseModel
from yt_dlp import YoutubeDL
import librosa
import numpy as np

from omega.constants import FIVE_MINUTES

Expand Down
6 changes: 3 additions & 3 deletions purchase_focus_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def display_videos(videos_data):
for idx, video in enumerate(videos_data, 1):
# Convert created_at to a more readable format
created_at = datetime.fromisoformat(video["created_at"].replace("Z", "+00:00"))
formatted_date = created_at.strftime("%Y-%m-%d %H:%M:%S")
created_at.strftime("%Y-%m-%d %H:%M:%S")

table_data.append(
[
Expand Down Expand Up @@ -222,7 +222,7 @@ def get_wallet(wallet_name=None, wallet_hotkey=None, wallet_path=None):

wallet = btcli_wallet(name=name, hotkey=hotkey_name, path=path)
try:
hotkey = wallet.get_hotkey()
wallet.get_hotkey()
except Exception as e:
print(f"{RED}Error loading hotkey: {e} {RESET}")
return
Expand Down Expand Up @@ -427,7 +427,7 @@ def select_order_for_verification():
while True:
if purchases:
print(
f"*** NOTE: A purchase is finalized when the purchase state is 'verified'. ***"
"*** NOTE: A purchase is finalized when the purchase state is 'verified'. ***"
)
choice = input(
f"{CYAN}Enter the number of the order to verify, 'm' for manual input, or 'n' to cancel: {RESET}"
Expand Down
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[lint]
ignore=["E722"]
10 changes: 2 additions & 8 deletions test_audio_dataset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
from datasets import load_dataset
from huggingface_hub import login
from io import BytesIO
import soundfile as sf
import numpy as np
import pandas as pd

# Set HF_TOKEN environment variable or pass directly
HF_TOKEN = os.getenv("HF_TOKEN")
Expand All @@ -26,10 +27,6 @@
else:
print(f"{key}: {first_row[key]}")


import librosa
import numpy as np

breakpoint()
audio_bytes = first_row["audio_bytes"]
audio_arr, sr = sf.read(BytesIO(audio_bytes))
Expand Down Expand Up @@ -81,9 +78,6 @@
}
)

# Convert to pandas DataFrame and save as CSV
import pandas as pd

df = pd.DataFrame(diarization_data)
os.makedirs("Dataset_audios/Metadata", exist_ok=True)
df.to_csv(f"Dataset_audios/Metadata/{youtube_id}_diarization.csv", index=False)
Loading