X-LANCE / SLAM-LLM

Speech, Language, Audio, Music Processing with Large Language Model
MIT License
511 stars 43 forks source link

repeated codes #120

Closed fclearner closed 2 months ago

fclearner commented 2 months ago

System Info

None

Information

🐛 Describe the bug

Hello,

Thank you for your excellent work on llm-asr.

I've been conducting some experiments with SLAM-LLM recently and encountered a peculiar section in the model initialization code, specifically the model factory function:

from slam_llm.utils.dataset_utils import load_module_from_py_file
from pathlib import Path

def get_custom_model_factory(model_config, logger):
    costom_model_path = model_config.get(
        "file", None
    )
    if costom_model_path is None:
        from slam_llm.models.slam_model import model_factory
        return model_factory

    if ":" in costom_model_path:
        module_path, func_name = costom_model_path.split(":")
    else:
        module_path, func_name = costom_model_path, "model_factory"

    if not module_path.endswith(".py"):
        raise ValueError(f"Dataset file {module_path} is not a .py file.")

    module_path = Path(module_path)
    if not module_path.is_file():
        raise FileNotFoundError(f"Dataset py file {module_path.as_posix()} does not exist or is not a file.")

    module = load_module_from_py_file(module_path.as_posix())
    try:
        return getattr(module, func_name)
    except AttributeError as e:
        logger.info(f"It seems like the given method name ({func_name}) is not present in the model .py file ({module_path.as_posix()}).")
        raise e

There are two model factory codes:

https://github.com/X-LANCE/SLAM-LLM/blob/683122402391806512a9d13febe8a952bb7c406e/src/slam_llm/models/slam_model.py#L21

https://github.com/X-LANCE/SLAM-LLM/blob/683122402391806512a9d13febe8a952bb7c406e/examples/asr_librispeech/model/slam_model_asr.py#L15

Do these serve any specific purpose?

I noticed that the two parts of the code are quite similar. Could you explain why they are organized in this manner?

Thank you in advance for your response

Error logs

None

Expected behavior

None

ddlBoJack commented 2 months ago

Hi, this design is for the expansibility. Code in slam_model.py is a base implementation and code in the examples is a succession. This makes sure different recipes have different task-specific design if needed.

fclearner commented 2 months ago

py is a base implement

thanks for the reply,

Hi, this design is for the expansibility. Code in slam_model.py is a base implementation and code in the examples is a succession. This makes sure different recipes have different task-specific design if needed.

Thanks for your explanation, It has been very helpful!