Skip to content

Commit 2f87fb7

Browse files
committed
fix: improve code quality and fix bugs
- Fix critical typo: torch.optim.adam -> torch.optim.Adam - Improve exception handling: bare except -> specific json.JSONDecodeError - Add proper NotImplementedError messages for placeholder classes - Add missing DatasetDict type hint in text_dataset.py - Add reference to AGENTS.md in CONTRIBUTING.md
1 parent 6405ddd commit 2f87fb7

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
We welcome and appreciate contributions to xTuring! Whether it's a bug fix, a new feature, or simply a typo, every little bit helps.
44

5+
Before starting, please skim the [Repository Guidelines](AGENTS.md) for project structure, local commands, style, and testing conventions.
6+
57
## Getting Started
68

79
1. Fork the repository on GitHub

src/xturing/datasets/text2image_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Text2ImageDataset:
66
config_name: str = "text2image_dataset"
77

88
def __init__(self, path: Union[str, Path]):
9-
pass
9+
raise NotImplementedError("Text2ImageDataset is not implemented yet.")
1010

1111
def _validate(self):
12-
pass
12+
raise NotImplementedError

src/xturing/datasets/text_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TextDatasetMeta:
1616
class TextDataset(BaseDataset):
1717
config_name: str = "text_dataset"
1818

19-
def __init__(self, path: Union[str, Path, HFDataset, dict]):
19+
def __init__(self, path: Union[str, Path, HFDataset, DatasetDict, dict]):
2020
if isinstance(path, HFDataset) or isinstance(path, DatasetDict):
2121
self.data = path
2222
elif isinstance(path, dict):

src/xturing/models/stable_diffusion.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@ class StableDiffusion:
88
config_name: str = "stable_diffusion"
99

1010
def __init__(self, weights_path: str):
11-
pass
11+
raise NotImplementedError(
12+
"StableDiffusion is a placeholder and not yet implemented."
13+
)
1214

1315
def finetune(self, dataset: Text2ImageDataset, logger=True):
1416
"""Finetune Stable Diffusion model on a given dataset.
15-
17+
1618
Args:
1719
dataset (Text2ImageDataset): Dataset to finetune on.
18-
logger (bool, optional): To be setup with a Pytorch Lightning logger when implemented."""
19-
pass
20+
logger (bool, optional): To be setup with a Pytorch Lightning logger when implemented.
21+
"""
22+
raise NotImplementedError
2023

2124
def generate(
2225
self,
2326
texts: Optional[Union[List[str], str]] = None,
2427
dataset: Optional[Text2ImageDataset] = None,
2528
):
26-
pass
29+
raise NotImplementedError
2730

2831
def save(self, path: Union[str, Path]):
29-
pass
32+
raise NotImplementedError

src/xturing/self_instruct/generate_instances.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def generate_instances(
6262
try:
6363
data = json.loads(line)
6464
existing_requests[data["instruction"]] = data
65-
except:
66-
pass
65+
except json.JSONDecodeError:
66+
# Skip malformed JSON lines
67+
continue
6768
print(f"Loaded {len(existing_requests)} existing requests")
6869

6970
progress_bar = tqdm(total=len(tasks))

src/xturing/self_instruct/identify_if_classification.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ def identify_if_classification(
4040
try:
4141
data = json.loads(line)
4242
existing_requests[data["instruction"]] = data
43-
except:
44-
pass
43+
except json.JSONDecodeError:
44+
# Skip malformed JSON lines
45+
continue
4546
print(f"Loaded {len(existing_requests)} existing requests")
4647

4748
# Create the progress bar

src/xturing/trainers/lightning_trainer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def configure_optimizers(self):
4747
self.pytorch_model.parameters(), lr=self.learning_rate
4848
)
4949
elif self.optimizer_name == "adam":
50-
optimizer = torch.optim.adam(
50+
optimizer = torch.optim.Adam(
5151
self.pytorch_model.parameters(), lr=self.learning_rate
5252
)
5353
elif self.optimizer_name == "cpu_adam":

0 commit comments

Comments
 (0)