Under Cal. Code
Civ. Pro. 580d, a deed of trust forclosure operates as a bar to a deficiency judgment (exception: FHA or VA loan guarantees preempt California state law).
However, if there is a junior lien on the same property, that lender can sue for a deficiency, because it was not foreclosed (exception: if the junior lien was purchase money, paid to seller in escrow, and the property was 1-4 unit residential, and the loan was made with the intent that it would be owner occupied, then it, too, is barred from a deficiency judgment under Code Civ. Pro. 580b).
In sum, if you have one conventional loan on the property and it is sold by trustee's sale, then no deficiency judgment is possible.
That said, if you give the lender a deed in lieu, then that completely avoids CCP 580b and 580d, because there is no forced sale. Which means that unless you get an unconditional release from liability on the unpaid loan balance, then the lender can obtain a deficiency judgment.
Also, your bankruptcy plan relieves you of some or all of the debt, regardless of any of the above. Exactly how much or on what terms depends on the plan.
Hope this helps.