mirror of
https://github.com/SakanaAI/doc-to-lora.git
synced 2026-07-23 17:01:04 +02:00
formatting
This commit is contained in:
parent
58393b862b
commit
85fa875a54
9 changed files with 43 additions and 45 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import json
|
||||
import random
|
||||
from typing import List, Dict
|
||||
import os
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def save_jsonl(data: List[Dict], filepath: str) -> None:
|
||||
def save_jsonl(data: list[dict], filepath: str) -> None:
|
||||
"""Save data to a JSONL file."""
|
||||
parent_dir = os.path.dirname(filepath)
|
||||
if parent_dir: # Only create directories if there's a parent path
|
||||
|
|
@ -16,7 +16,7 @@ def save_jsonl(data: List[Dict], filepath: str) -> None:
|
|||
f.write("\n")
|
||||
|
||||
|
||||
def get_random_combinations(numbers: List[int], n: int, k: int) -> List[List[int]]:
|
||||
def get_random_combinations(numbers: list[int], n: int, k: int) -> list[list[int]]:
|
||||
"""Get n random combinations of k numbers from the list."""
|
||||
# using itertools.combinations hangs with large numbers
|
||||
# so we explicitly generate the n indices
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import json
|
||||
import random
|
||||
from typing import List, Dict
|
||||
import os
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def save_jsonl(data: List[Dict], filepath: str) -> None:
|
||||
def save_jsonl(data: list[dict], filepath: str) -> None:
|
||||
"""Save data to a JSONL file."""
|
||||
parent_dir = os.path.dirname(filepath)
|
||||
if parent_dir: # Only create directories if there's a parent path
|
||||
|
|
@ -16,7 +16,7 @@ def save_jsonl(data: List[Dict], filepath: str) -> None:
|
|||
f.write("\n")
|
||||
|
||||
|
||||
def get_random_combinations(numbers: List[int], n: int, k: int) -> List[List[int]]:
|
||||
def get_random_combinations(numbers: list[int], n: int, k: int) -> list[list[int]]:
|
||||
"""Get n random combinations of k numbers from the list."""
|
||||
# using itertools.combinations hangs with large numbers
|
||||
# so we explicitly generate the n indices
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import json
|
||||
import random
|
||||
from typing import List, Dict
|
||||
import os
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def save_jsonl(data: List[Dict], filepath: str) -> None:
|
||||
def save_jsonl(data: list[dict], filepath: str) -> None:
|
||||
"""Save data to a JSONL file."""
|
||||
parent_dir = os.path.dirname(filepath)
|
||||
if parent_dir: # Only create directories if there's a parent path
|
||||
|
|
@ -16,7 +16,7 @@ def save_jsonl(data: List[Dict], filepath: str) -> None:
|
|||
f.write("\n")
|
||||
|
||||
|
||||
def get_random_combinations(numbers: List[int], n: int, k: int) -> List[List[int]]:
|
||||
def get_random_combinations(numbers: list[int], n: int, k: int) -> list[list[int]]:
|
||||
"""Get n random combinations of k numbers from the list."""
|
||||
# using itertools.combinations hangs with large numbers
|
||||
# so we explicitly generate the n indices
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import json
|
||||
import random
|
||||
from typing import List, Dict
|
||||
import os
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def save_jsonl(data: List[Dict], filepath: str) -> None:
|
||||
def save_jsonl(data: list[dict], filepath: str) -> None:
|
||||
"""Save data to a JSONL file."""
|
||||
parent_dir = os.path.dirname(filepath)
|
||||
if parent_dir: # Only create directories if there's a parent path
|
||||
|
|
@ -16,7 +16,7 @@ def save_jsonl(data: List[Dict], filepath: str) -> None:
|
|||
f.write("\n")
|
||||
|
||||
|
||||
def get_random_combinations(numbers: List[int], n: int, k: int) -> List[List[int]]:
|
||||
def get_random_combinations(numbers: list[int], n: int, k: int) -> list[list[int]]:
|
||||
"""Get n random combinations of k numbers from the list."""
|
||||
# using itertools.combinations hangs with large numbers
|
||||
# so we explicitly generate the n indices
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import json
|
||||
import random
|
||||
from typing import List, Dict
|
||||
import os
|
||||
import random
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def save_jsonl(data: List[Dict], filepath: str) -> None:
|
||||
def save_jsonl(data: list[dict], filepath: str) -> None:
|
||||
"""Save data to a JSONL file."""
|
||||
parent_dir = os.path.dirname(filepath)
|
||||
if parent_dir: # Only create directories if there's a parent path
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
from collections import defaultdict
|
||||
from copy import copy
|
||||
from functools import partial
|
||||
from importlib.resources import read_binary
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from collections import defaultdict
|
||||
from copy import copy
|
||||
from functools import partial
|
||||
from importlib.resources import read_binary
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
|
@ -18,9 +18,10 @@ from data_utils import (
|
|||
tokenize_chat_messages,
|
||||
tokenize_ctx_text,
|
||||
)
|
||||
from datasets import load_dataset, disable_caching
|
||||
from datasets import disable_caching, load_dataset
|
||||
from model_loading import get_lora_config, get_model_and_tokenizer
|
||||
from modeling_utils import HyperLoRA, ModulatedPretrainedModel, get_hypernet_config
|
||||
from rouge_score import rouge_scorer
|
||||
from training_utils import TRAINING_TASK, train_model
|
||||
from transformers import (
|
||||
AutoModelForCausalLM,
|
||||
|
|
@ -30,7 +31,6 @@ from transformers import (
|
|||
HfArgumentParser,
|
||||
TrainingArguments,
|
||||
)
|
||||
from rouge_score import rouge_scorer
|
||||
from utils import (
|
||||
extract_cli_args,
|
||||
get_run_name,
|
||||
|
|
@ -44,10 +44,10 @@ from utils import (
|
|||
from configs import (
|
||||
ArgumentParser,
|
||||
CtxTrainingArguments,
|
||||
DataArguments,
|
||||
ExperimentSetup,
|
||||
LoRAArguments,
|
||||
ModelArguments,
|
||||
DataArguments,
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ from enum import Enum
|
|||
import numpy as np
|
||||
from transformers import (
|
||||
GenerationConfig,
|
||||
Trainer,
|
||||
Seq2SeqTrainer,
|
||||
Seq2SeqTrainingArguments,
|
||||
Trainer,
|
||||
)
|
||||
from transformers.trainer_utils import get_last_checkpoint
|
||||
|
||||
|
||||
TRAINING_TASK = Enum("TRAINING_TASK", ["CAUSAL_LM", "COMPLETION"])
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
import ast
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
import yaml
|
||||
import logging
|
||||
from contextlib import contextmanager
|
||||
from typing import Iterable, Optional
|
||||
|
||||
|
||||
import torch
|
||||
import yaml
|
||||
from peft import PeftConfig, PeftModel
|
||||
from peft.tuners.tuners_utils import BaseTunerLayer, check_target_module_exists
|
||||
from peft.utils import get_peft_model_state_dict
|
||||
|
|
|
|||
12
webui/app.py
12
webui/app.py
|
|
@ -1,9 +1,9 @@
|
|||
import os
|
||||
import json
|
||||
import os
|
||||
|
||||
import torch
|
||||
import yaml
|
||||
from flask import Flask, render_template, request, abort, jsonify
|
||||
from flask import Flask, abort, jsonify, render_template, request
|
||||
from transformers import pipeline
|
||||
|
||||
app = Flask(__name__)
|
||||
|
|
@ -27,7 +27,7 @@ def get_run_data(run_path):
|
|||
"""
|
||||
results_file = os.path.join(run_path, "all_results.json")
|
||||
try:
|
||||
with open(results_file, "r") as f:
|
||||
with open(results_file) as f:
|
||||
data = json.load(f)
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
|
|
@ -59,7 +59,7 @@ def get_generated_text_data(run_path):
|
|||
filename = f"{split}_generated_text.jsonl"
|
||||
filepath = os.path.join(run_path, filename)
|
||||
try:
|
||||
with open(filepath, "r") as f:
|
||||
with open(filepath) as f:
|
||||
lines = f.readlines()
|
||||
data = [json.loads(line) for line in lines]
|
||||
generated_data[split] = data
|
||||
|
|
@ -103,7 +103,7 @@ def visualize(run):
|
|||
# Load config.yaml from the run directory
|
||||
config_path = os.path.join(logdir, "config.yaml")
|
||||
try:
|
||||
with open(config_path, "r") as f:
|
||||
with open(config_path) as f:
|
||||
config = yaml.safe_load(f)
|
||||
model_name = config.get("model_name_or_path")
|
||||
except FileNotFoundError:
|
||||
|
|
@ -133,7 +133,7 @@ def load_model():
|
|||
logdir = os.path.join(TRAIN_OUTPUTS_DIR, run)
|
||||
config_path = os.path.join(logdir, "config.yaml")
|
||||
try:
|
||||
with open(config_path, "r") as f:
|
||||
with open(config_path) as f:
|
||||
config = yaml.safe_load(f)
|
||||
chat_model_name = config.get("model_name_or_path")
|
||||
except FileNotFoundError:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue