Skip to content
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

problem with model loading #13

Open
SimpleNumber opened this issue Jun 30, 2023 · 14 comments
Open

problem with model loading #13

SimpleNumber opened this issue Jun 30, 2023 · 14 comments

Comments

@SimpleNumber
Copy link

Hi AlphaLink developers!

I am trying to use AlphaLink. I've downloaded the model via your dropbox link and unpacked it with gunzip. So I start the prediction like this:

 python predict_with_crosslinks.py ./test/test/input.fasta ./test/test/restraints.txt --distograms --checkpoint_path ./alphalink/resources/finetuning_model_5_ptm_CACA_10A.pt --uniref90_database_path /resources/alphafold2/uniref90/uniref90.fasta --mgnify_database_path /resources/alphafold2/mgnify/mgy_clusters.fa --pdb70_database_path /resources/alphafold2/pdb70/ --uniclust30_database_path /resources/alphafold2/uniclust30/uniclust30_2018_08/

The traceback I've got:

  File "/users/user/alphalink/AlphaLink/predict_with_crosslinks.py", line 571, in <module>  main(args)
  File "/users/user/alphalink/AlphaLink/predict_with_crosslinks.py", line 376, in main model, output_directory = load_models_from_command_line(args, config)
  File "/users/user/alphalink/AlphaLink/predict_with_crosslinks.py", line 271, in load_models_from_command_line model.load_state_dict(sd)
  File "/software/f2021/software/pytorch/1.10.0-foss-2021a-cuda-11.3.1/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1482, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for AlphaFold:
        size mismatch for xl_embedder.linear.weight: copying a param with shape torch.Size([128, 1]) from checkpoint, the shape in current model is torch.Size([128, 128]).

Do you have any ideas about what went wrong?:)

Best regards,
Julia

@lhatsk
Copy link
Owner

lhatsk commented Jun 30, 2023

Hi Julia,

You are using the distogram flag with the contact network. In case your restraints are just contacts, you should remove the --distogram flag or if you want to use the distogram network, you need to use the other network weights: finetuning_model_5_ptm_distogram.pt

@SimpleNumber
Copy link
Author

SimpleNumber commented Jun 30, 2023

Thank you for a prompt response!

I've used an example that you have in read.me:

     python predict_with_crosslinks.py 7K3N_A.fasta restraints.csv --distograms --checkpoint_path resources/AlphaLink_params/finetuning_model_5_ptm_CACA_10A.pt --uniref90_database_path uniref90.fasta --mgnify_database_path mgy_clusters.fa --pdb70_database_path pdb70/pdb70 --uniclust30_database_path uniclust30_2018_08/uniclust30_2018_08

Here I have one more question: should the restrains.csv file be the one that preprocessing_distributions.py produces? If so, in this file there is no info about cross-linked amino acids anymore...

In the article, you give a very nice example with T1064, can you please share the input file for this prediction? I am basically trying to repeat your results:)

Best,
Julia

@lhatsk
Copy link
Owner

lhatsk commented Jun 30, 2023

No, it doesn't have to be produced by preprocessing_distributions.py, but it has to contain a distogram. contacts_to_distograms.py would also work or you generate one manually. All the input files only include residue positions, esp. the distogram network is amino acid-agnostic. If you want to have residue-residue-specific distograms you would need to combine multiple distograms.

Note that the T1064 example was done with the contact network. You can find the features and crosslinks for some predictions on modelarchive, e.g., this one should be very close in performance: https://modelarchive.org/doi/10.5452/ma-rap-alink-1259 The pickled feature file can be used with --features

@SimpleNumber
Copy link
Author

Sorry, I didn't get how the input file should look like. Could you pls give an example?

Note that the T1064 example was done with the contact network. You can find the features and crosslinks for some predictions on modelarchive, e.g., this one should be very close in performance: https://modelarchive.org/doi/10.5452/ma-rap-alink-1259 The pickled feature file can be used with --features

this one I also didn't get this, sorry:( There are no csv files at all. I am not so experienced in the field. Could you pls give a more detailed explanation?

Thank you in advance,
Julia

@lhatsk
Copy link
Owner

lhatsk commented Jun 30, 2023

Here I have one more question: should the restrains.csv file be the one that preprocessing_distributions.py produces?

Sorry, didn't properly address this. Yes, restraints.csv would be the output of the script.

Sorry, I didn't get how the input file should look like. Could you pls give an example?

The CSV input to the distogram network looks something like this:

residueFrom residueTo 1..128
128 163 0.05 0.05 0.05 0.05 ...

Columns 2-130 contain the probability of each bin in a distogram going from 2.3125 to 42 Angstrom. The 128th bin is a catch-all bin for distances >= 42.
The first two columns are your residue positions (starting from 1).

this one I also didn't get this, sorry:( There are no csv files at all. I am not so experienced in the field. Could you pls give a more detailed explanation?

In the associated data zip-file under Downloads are two inputs, both are already preprocessed so it skips the CSV part.

T1064.pkl contains the features (including MSAs) and T1064_8_LEU_10A_CA.pt contains the crosslinks. You can use them directly to sidestep the feature generation etc. like so (untested):

python predict_with_crosslinks.py T1064.fasta T1064_8_LEU_10A_CA.pt --features T1064.pkl --checkpoint_path resources/AlphaLink_params/finetuning_model_5_ptm_CACA_10A.pt --uniref90_database_path uniref90.fasta --mgnify_database_path mgy_clusters.fa --pdb70_database_path pdb70/pdb70 --uniclust30_database_path uniclust30_2018_08/uniclust30_2018_08

@SimpleNumber
Copy link
Author

Hi there!

I am back to try to make AlphaLink work:)
Sorry for this lengthy discussion. And thank you for your help! However, it still doesn't work.

Now, I use this histogram mode. So restraints.csv looks like a table with 130 columns:
128 163 0.05 0.05 0.05 0.05 ...
147 77 0.01 0.015 0.05 0.05 ...
147 41 0.04 0.1 0.05 0.052 ...

I use this command:

 python predict_with_crosslinks.py /users/julia/alphalink/test/test/input.fasta /users/julia/alphalink/test/test/restrains_distr.csv --distograms --checkpoint_path /users/julia/alphalink/resources/finetuning_model_5_ptm_distogram.pt --uniref90_database_path /resources/alphafold2/uniref90/uniref90.fasta --mgnify_database_path /resources/alphafold2/mgnify/mgy_clusters.fa --pdb70_database_path /resources/alphafold2/pdb70/ --uniclust30_database_path /resources/alphafold2/uniclust30/uniclust30_2018_08/

This command gives me the following traceback:

INFO:/users/julia/alphalink/AlphaLink/predict_with_crosslinks.py:Loaded OpenFold parameters at /users/julia/alphalink/resources/finetuning_model_5_ptm_distogram.pt...
INFO:/users/julia/alphalink/AlphaLink/predict_with_crosslinks.py:Using precomputed alignments for bsa1 at /users/julia/alphalink/AlphaLink/alignments...
INFO:/users/julia/alphalink/AlphaLink/predict_with_crosslinks.py:Loaded 3 restraints...
Killed

since there is no error, I am puzzled. Why is it killed? Do you have any ideas about what could go wrong?

Best regards,
Julia

@lhatsk
Copy link
Owner

lhatsk commented Aug 9, 2023

Sorry, I have absolutely no idea. Never seen this before. Are you somehow resources constrained? Like running out of memory? Is this target very large? If you are able to share the data, I could run it locally to verify.

@SimpleNumber
Copy link
Author

It is a dummy example that I am trying to make work. Under this link the files that I've used. Let me know if you can't access the folder.

Thank you for your help!
cheers,
J

@lhatsk
Copy link
Owner

lhatsk commented Aug 14, 2023

Sorry, I'm out sick. Won't be able to test it before next week. But killed points towards some external event since the process seemed to be killed.

@lhatsk
Copy link
Owner

lhatsk commented Aug 22, 2023

Worked fine for me. Required 18G of GPU memory.

INFO:predict_with_crosslinks.py:Loaded OpenFold parameters at resources/AlphaLink_params/finetuning_model_5_ptm_distogram.pt...
INFO:predict_with_crosslinks.py:Loaded 3 restraints...
INFO:predict_with_crosslinks.py:Running inference for bsa1...
INFO:predict_with_crosslinks.py:Inference time: 498.2697855802253
INFO:predict_with_crosslinks.py:Output written to bsa1_model_5_ptm_crosslinks_unrelaxed.pdb...
INFO:predict_with_crosslinks.py:Relaxed output written to bsa1_model_5_ptm_crosslinks_relaxed.pdb...

bsa1_model_5_ptm_crosslinks_relaxed.pdb.zip

@SimpleNumber
Copy link
Author

Apparently there is a problem with my server..it just kills the process. I will try to figure out what is wrong.

Thank you for your help! The tool is really cool!:)

Cheers,
Julia

@lhatsk
Copy link
Owner

lhatsk commented Aug 24, 2023

Do you run it locally or is it submitted to some compute nodes with, e.g., SLURM?

@audrizzle
Copy link

audrizzle commented Feb 13, 2025

Hello AlphaLink developers,

I am trying to use the T1064 data from ModelArchive to run AlphaLink migrate-to-openfold-1.0 with the following:

python predict_with_crosslinks.py practice_fasta practice/T1064_8_LEU_10A_CA.pt --features practice/T1064.pkl --checkpoint_path resources/AlphaLink_params/finetuning_model_5_ptm_distogram_1.0.pt --uniref90_database_path resources/uniref90 --mgnify_database_path resources/mgnify --pdb70_database_path resources/pdb70 --uniclust30_database_path resources/uniclust30_2018_08 &> foo9.txt

And the output indicates that I am "Missing key(s) in state_dict:" (link to output).

Also, as a separate issue, I'm unable to run the test.test_model unit test. I was able to run the analogous unit test in my openfold installation in a separate conda environment, but not in my AlphaLink with my AlphaLink environment:
`(openfold_venv) ak@gpudev1:~/software/AlphaLink$ scripts/run_unit_tests.sh -v tests.test_model
test_compare (tests.test_model.TestModel) ... skipped 'Requires AlphaFold'
test_dry_run (tests.test_model.TestModel) ... FAIL

======================================================================
FAIL: test_dry_run (tests.test_model.TestModel)

Traceback (most recent call last):
File "/wynton/home/wiita/akishi/software/AlphaLink/tests/test_model.py", line 91, in test_dry_run
out = model(batch)
File "/wynton/home/wiita/akishi/.conda/envs/openfold_venv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/wynton/home/wiita/akishi/software/AlphaLink/openfold/model/model.py", line 520, in forward
_recycle=(num_iters > 1)
File "/wynton/home/wiita/akishi/software/AlphaLink/openfold/model/model.py", line 322, in iteration
inplace_safe=inplace_safe,
File "/wynton/home/wiita/akishi/software/AlphaLink/openfold/model/model.py", line 177, in embed_templates
_mask_trans=self.config._mask_trans,
File "/wynton/home/wiita/akishi/.conda/envs/openfold_venv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/wynton/home/wiita/akishi/software/AlphaLink/openfold/model/template.py", line 389, in forward
assert(not self.training)
AssertionError


Ran 2 tests in 0.834s

FAILED (failures=1, skipped=1)

Test(s) failed. Make sure you've installed all Python dependencies.
`

Any help would be greatly appreciated! Thanks.

Sincerely,
Audrey

@lhatsk
Copy link
Owner

lhatsk commented Feb 13, 2025

Hi Audrey,

I can't find the part about "missing keys" in the output. The CUDA error points towards something else, although I don't know what. The migrate-to-openfold-1.0 hasn't been maintained, I would suggest switching to the main branch.

I have never run the tests before. These are the original OpenFold tests. They were not updated for AlphaLink. The error indicates that some dependencies are missing. You will probably also run into issues since there are no crosslink inputs in the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants