-
Notifications
You must be signed in to change notification settings - Fork 47
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
P3-Find a better way for including rank_llm in sys path. #53
Comments
I can handle this with relative paths. Would that be preferred over the current snippet? |
Relative or absolute path would be still the same, @wu-ming233 if you are interested in this problem. Try looking for solutions that don't require adding path at the beginning of every file that needs it. |
By relative imports, I meant imports such as: from ..retrieve.indices_dict import INDICES
from ..retrieve.topics_dict import TOPICS as opposed to, say, SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
parent = os.path.dirname(SCRIPT_DIR)
parent = os.path.dirname(parent)
sys.path.append(parent)
from rank_llm.result import Result, ResultsWriter
from rank_llm.retrieve.indices_dict import INDICES
from rank_llm.retrieve.topics_dict import TOPICS Do you think that will be preferred? |
I feel relative imports are fine internally, this is what transformers does from what I remember. What about generally relying more on init.py for conveniently importing modules besides this? @sahel-sh |
"Remember that you should generally opt for absolute imports over relative ones, unless the path is complex and would make the statement too long" this is from real python: https://realpython.com/absolute-vs-relative-python-imports/#:~:text=With%20your%20new%20skills%2C%20you,make%20the%20statement%20too%20long. @wu-ming233 In general I would like to keep the imports as absolute path. I will try a relative path in one of the demos. If the demo is still runnable both from a cloned repo and by importing rankllm after installing it as a package, I will let you know and you can update every thing script that does add to the path explicitly? |
If we were to use relative imports, one can call our scripts as modules, respecting the package structure, such as:
which would work if the user calls from the directory I am still looking for ways that could handle imports more elegantly, but most of them don't seem to be as robust as just using the somewhat dirty |
Currently we add the following snippet to every script that we want to run both from a cloned repo and using package installation.
Ideally we should find a cleaner/simpler way
The text was updated successfully, but these errors were encountered: