Repository navigation
Description
@daichengxin The current container for quantms-rescoring and the ms2rescore steps and ms2rescore and fine-tunning are not working properly. I think we have to review the entire container; tested it in multiple enviroments and then included it in quantms back.
The error reported by @jpfeuffer I also saw it; I have tried to fixed with another solution:
containerOptions workflow.containerEngine == 'docker' ?
'-u $(id -u) -e "HOME=${HOME}" -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -v $HOME:$HOME' :
''
But it doesn't work in singularity and @jpfeuffer also commented that is not a good solution; I think @jonasscheid use it something similar in mhcquant.
The problem:
The error boils down to one line deep in PyTorch's initialization:
torch/_inductor/runtime/cache_dir_utils.py:23
getpass.getuser() # → pwd.getpwuid(os.getuid()) → KeyError: uid 1001 not found
Here's the full chain of what happens:
-
Import cascade triggers the crash
The quantms-rescoring container imports peptdeep, which pulls in transformers, which pulls in torch. During module-level initialization (not at function call time), PyTorch's torch._dynamo eagerly creates a disk cache directory. To build the cache path, it calls getpass.getuser(). -
getpass.getuser() fallback chain
Python's getpass.getuser() tries these in order:
$LOGNAME env var
$USER env var
$LNAME env var
$USERNAME env var
Last resort: pwd.getpwuid(os.getuid()) — this is the one that crashes
If none of the env vars are set, it falls through to getpwuid(), which looks up the UID in /etc/passwd.
This is the current solution proposed by @jpfeuffer:
"""
# Fix for UID-less environments (GitHub Actions, OpenShift, etc.)
# where pwd.getpwuid() fails because the running UID has no /etc/passwd entry.
# Python's getpass.getuser() calls getpwuid() only when USER env var is unset.
if [ -w /etc/passwd ]; then
echo "\${USER:-quantms}:x:\$(id -u):\$(id -g):\${USER:-quantms} user:/tmp:/bin/bash" >> /etc/passwd
fi
export USER="\${USER:-quantms}"
export LOGNAME="\${LOGNAME:-\${USER:-quantms}}"
export LNAME="\${LNAME:-\${USER:-quantms}}"
export USERNAME="\${USERNAME:-\${USER:-quantms}}"
export HOME="\${HOME:-\$PWD}"
export TORCHINDUCTOR_CACHE_DIR="\${TORCHINDUCTOR_CACHE_DIR:-\$PWD/.torchinductor_cache}"
mkdir -p "\$TORCHINDUCTOR_CACHE_DIR"
But I think we should fix the container. @daichengxin @jpfeuffer can we discuss the solution?
Description of the bug
Command error:
File "/usr/local/lib/python3.11/site-packages/quantmsrescore/annotator.py", line 14, in <module>
from quantmsrescore.alphapeptdeep import AlphaPeptDeepAnnotator
File "/usr/local/lib/python3.11/site-packages/quantmsrescore/alphapeptdeep.py", line 2, in <module>
from peptdeep.pretrained_models import ModelManager
File "/usr/local/lib/python3.11/site-packages/peptdeep/pretrained_models.py", line 31, in <module>
from peptdeep.model.ms2 import (
File "/usr/local/lib/python3.11/site-packages/peptdeep/model/__init__.py", line 1, in <module>
from peptdeep.model import (
File "/usr/local/lib/python3.11/site-packages/peptdeep/model/base.py", line 2, in <module>
from peptdeep.model.building_block import *
File "/usr/local/lib/python3.11/site-packages/peptdeep/model/building_block.py", line 5, in <module>
from transformers.models.bert.modeling_bert import BertEncoder
File "/usr/local/lib/python3.11/site-packages/transformers/models/bert/modeling_bert.py", line 27, in <module>
from ...generation import GenerationMixin
File "<frozen importlib._bootstrap>", line 1229, in _handle_fromlist
File "/usr/local/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 2098, in __getattr__
module = self._get_module(self._class_to_module[name])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 2288, in _get_module
raise e
File "/usr/local/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 2286, in _get_module
return importlib.import_module("." + module_name, self.__name__)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/transformers/generation/utils.py", line 44, in <module>
from ..masking_utils import create_masks_for_generate
File "/usr/local/lib/python3.11/site-packages/transformers/masking_utils.py", line 39, in <module>
from torch._dynamo._trace_wrapped_higher_order_op import TransformGetItemToIndex
File "/usr/local/lib/python3.11/site-packages/torch/_dynamo/__init__.py", line 13, in <module>
from . import (
File "/usr/local/lib/python3.11/site-packages/torch/_dynamo/aot_compile.py", line 16, in <module>
from torch._dynamo.package import SystemInfo
File "/usr/local/lib/python3.11/site-packages/torch/_dynamo/package.py", line 1157, in <module>
DynamoCache = DiskDynamoCache(os.path.join(cache_dir(), "dynamo"))
^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/torch/_dynamo/package.py", line 1154, in cache_dir
return cache_dir()
^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/torch/_inductor/runtime/cache_dir_utils.py", line 17, in cache_dir
os.environ["TORCHINDUCTOR_CACHE_DIR"] = cache_dir = default_cache_dir()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/torch/_inductor/runtime/cache_dir_utils.py", line 23, in default_cache_dir
sanitized_username = re.sub(r'[\\/:*?"<>|]', "_", getpass.getuser())
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/getpass.py", line 169, in getuser
return pwd.getpwuid(os.getuid())[0]
^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'getpwuid(): uid not found: 1001'
Command used and terminal output
Relevant files
No response
System information
No response
Activity
[-]Finetuning completely broken[/-][+]ms2rescore container and fine-tunning not working properly[/+]daichengxin commentedon Feb 27, 2026
Yes, we should fix container. Can we specify cache dir in the package to solve it? For example:
ypriverol commentedon Feb 27, 2026
Waht do you mean in the package? Do you mean in the container?
daichengxin commentedon Feb 27, 2026
Set the cache path prior to importing in https://github.com/bigbio/quantms-rescoring/blob/main/quantmsrescore/alphapeptdeep.py
ypriverol commentedon Feb 27, 2026
I think if you hardcode paths like /tmp/torchinductor_cache within the container; then you will have problem in the enviroment outside that don't know that; also that path maybe needs to be map when running? @jpfeuffer can you advice here?
ypriverol commentedon Feb 28, 2026
Solution: 3-Layer Fix for UID-less Container Environments
After investigating the root cause, here's the designed solution and the changes already implemented.
Root Cause
PyTorch's
torch._dynamoeagerly callsgetpass.getuser()at import time, which falls back topwd.getpwuid(os.getuid()). In containers running with arbitrary UIDs (GitHub Actions uid 1001, OpenShift random UIDs), there's no/etc/passwdentry for the running UID, causing aKeyError.The key insight:
getpass.getuser()checks environment variables ($LOGNAME,$USER,$LNAME,$USERNAME) before callinggetpwuid(). So settingUSERenv var prevents the fallback entirely.Solution: 3-Layer Defense
Layer 1: Package-level fix (Root cause fix) —
quantmsrescore/__init__.pyThis is the primary fix. At the very top of the package (before any torch/peptdeep imports):
This works regardless of container engine, CI system, or how the tool is invoked.
Layer 2: Dockerfile defaults
Provides sane defaults in the container image itself:
The
chmod g+w /etc/passwdallows the script-level workaround (Layer 3) to add a passwd entry if needed, which is the OpenShift-recommended pattern.Layer 3: Nextflow script-level workaround (Safety net)
The existing workaround in the Nextflow process scripts (
msrescore_features/main.nf,msrescore_fine_tuning/main.nf) acts as a safety net:This can be simplified or removed once Layer 1 + Layer 2 are confirmed working in the new container release.
Security improvement
The previous
containerOptionsapproach that bind-mounted/etc/passwd,/etc/group,/etc/shadow, and$HOMEfrom the host into the container has been removed (flagged by Copilot security review). The 3-layer approach above is self-contained within the container and doesn't require any host filesystem access.Status
quantmsrescore/__init__.py— implementedcontainerOptionsremoved frommsrescore_featuresandmsrescore_fine_tuningquantms-rescoring:0.0.15with Layers 1+2